rugged 1.0.1 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (349) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +1 -0
  3. data/README.md +1 -1
  4. data/ext/rugged/rugged.c +7 -4
  5. data/ext/rugged/rugged_commit.c +1 -1
  6. data/ext/rugged/rugged_object.c +1 -1
  7. data/ext/rugged/rugged_repo.c +3 -3
  8. data/lib/rugged/commit.rb +16 -2
  9. data/lib/rugged/repository.rb +2 -2
  10. data/lib/rugged/version.rb +1 -1
  11. data/vendor/libgit2/CMakeLists.txt +41 -74
  12. data/vendor/libgit2/COPYING +109 -1
  13. data/vendor/libgit2/cmake/{Modules/AddCFlagIfSupported.cmake → AddCFlagIfSupported.cmake} +0 -0
  14. data/vendor/libgit2/cmake/{Modules/EnableWarnings.cmake → EnableWarnings.cmake} +0 -0
  15. data/vendor/libgit2/cmake/{Modules/FindCoreFoundation.cmake → FindCoreFoundation.cmake} +0 -0
  16. data/vendor/libgit2/cmake/{Modules/FindGSSAPI.cmake → FindGSSAPI.cmake} +0 -0
  17. data/vendor/libgit2/cmake/{Modules/FindGSSFramework.cmake → FindGSSFramework.cmake} +0 -0
  18. data/vendor/libgit2/cmake/{Modules/FindHTTP_Parser.cmake → FindHTTP_Parser.cmake} +0 -0
  19. data/vendor/libgit2/cmake/{Modules/FindIconv.cmake → FindIconv.cmake} +0 -0
  20. data/vendor/libgit2/cmake/FindLibSSH2.cmake +13 -0
  21. data/vendor/libgit2/cmake/{Modules/FindPCRE.cmake → FindPCRE.cmake} +0 -0
  22. data/vendor/libgit2/cmake/{Modules/FindPCRE2.cmake → FindPCRE2.cmake} +0 -0
  23. data/vendor/libgit2/cmake/{Modules/FindPkgLibraries.cmake → FindPkgLibraries.cmake} +0 -0
  24. data/vendor/libgit2/cmake/{Modules/FindSecurity.cmake → FindSecurity.cmake} +0 -0
  25. data/vendor/libgit2/cmake/{Modules/FindStatNsec.cmake → FindStatNsec.cmake} +0 -0
  26. data/vendor/libgit2/cmake/Findfutimens.cmake +14 -0
  27. data/vendor/libgit2/cmake/{Modules/FindmbedTLS.cmake → FindmbedTLS.cmake} +0 -0
  28. data/vendor/libgit2/cmake/{Modules/IdeSplitSources.cmake → IdeSplitSources.cmake} +0 -0
  29. data/vendor/libgit2/cmake/{Modules/PkgBuildConfig.cmake → PkgBuildConfig.cmake} +0 -0
  30. data/vendor/libgit2/cmake/{Modules/SanitizeBool.cmake → SanitizeBool.cmake} +0 -0
  31. data/vendor/libgit2/cmake/{Modules/SelectGSSAPI.cmake → SelectGSSAPI.cmake} +18 -26
  32. data/vendor/libgit2/cmake/{Modules/SelectHTTPSBackend.cmake → SelectHTTPSBackend.cmake} +29 -32
  33. data/vendor/libgit2/cmake/{Modules/SelectHashes.cmake → SelectHashes.cmake} +21 -28
  34. data/vendor/libgit2/deps/chromium-zlib/CMakeLists.txt +101 -0
  35. data/vendor/libgit2/deps/http-parser/CMakeLists.txt +4 -3
  36. data/vendor/libgit2/deps/ntlmclient/CMakeLists.txt +24 -10
  37. data/vendor/libgit2/deps/ntlmclient/compat.h +0 -27
  38. data/vendor/libgit2/deps/ntlmclient/crypt.h +14 -9
  39. data/vendor/libgit2/deps/ntlmclient/crypt_commoncrypto.c +20 -20
  40. data/vendor/libgit2/deps/ntlmclient/crypt_commoncrypto.h +3 -3
  41. data/vendor/libgit2/deps/ntlmclient/crypt_mbedtls.c +37 -36
  42. data/vendor/libgit2/deps/ntlmclient/crypt_mbedtls.h +4 -3
  43. data/vendor/libgit2/deps/ntlmclient/crypt_openssl.c +178 -51
  44. data/vendor/libgit2/deps/ntlmclient/crypt_openssl.h +74 -5
  45. data/vendor/libgit2/deps/ntlmclient/ntlm.c +164 -135
  46. data/vendor/libgit2/deps/ntlmclient/ntlm.h +13 -9
  47. data/vendor/libgit2/deps/ntlmclient/ntlmclient.h +16 -3
  48. data/vendor/libgit2/deps/ntlmclient/unicode.h +10 -4
  49. data/vendor/libgit2/deps/ntlmclient/unicode_builtin.c +16 -27
  50. data/vendor/libgit2/deps/ntlmclient/unicode_builtin.h +20 -0
  51. data/vendor/libgit2/deps/ntlmclient/unicode_iconv.c +28 -52
  52. data/vendor/libgit2/deps/ntlmclient/unicode_iconv.h +22 -0
  53. data/vendor/libgit2/deps/ntlmclient/util.c +15 -1
  54. data/vendor/libgit2/deps/ntlmclient/util.h +2 -1
  55. data/vendor/libgit2/deps/pcre/LICENCE +93 -0
  56. data/vendor/libgit2/deps/pcre/pcre.h +2 -2
  57. data/vendor/libgit2/deps/pcre/pcre_compile.c +29 -17
  58. data/vendor/libgit2/deps/pcre/pcre_jit_compile.c +4 -4
  59. data/vendor/libgit2/deps/pcre/pcreposix.c +2 -3
  60. data/vendor/libgit2/deps/zlib/CMakeLists.txt +6 -5
  61. data/vendor/libgit2/deps/zlib/deflate.c +1 -0
  62. data/vendor/libgit2/include/git2/annotated_commit.h +1 -1
  63. data/vendor/libgit2/include/git2/apply.h +2 -0
  64. data/vendor/libgit2/include/git2/attr.h +95 -0
  65. data/vendor/libgit2/include/git2/blame.h +95 -42
  66. data/vendor/libgit2/include/git2/blob.h +37 -3
  67. data/vendor/libgit2/include/git2/branch.h +25 -0
  68. data/vendor/libgit2/include/git2/cert.h +42 -5
  69. data/vendor/libgit2/include/git2/checkout.h +28 -12
  70. data/vendor/libgit2/include/git2/clone.h +1 -1
  71. data/vendor/libgit2/include/git2/commit.h +35 -19
  72. data/vendor/libgit2/include/git2/common.h +51 -6
  73. data/vendor/libgit2/include/git2/config.h +1 -1
  74. data/vendor/libgit2/include/git2/deprecated.h +368 -8
  75. data/vendor/libgit2/include/git2/diff.h +34 -113
  76. data/vendor/libgit2/include/git2/email.h +127 -0
  77. data/vendor/libgit2/include/git2/errors.h +8 -7
  78. data/vendor/libgit2/include/git2/filter.h +63 -17
  79. data/vendor/libgit2/include/git2/graph.h +20 -2
  80. data/vendor/libgit2/include/git2/index.h +4 -5
  81. data/vendor/libgit2/include/git2/indexer.h +2 -1
  82. data/vendor/libgit2/include/git2/notes.h +2 -2
  83. data/vendor/libgit2/include/git2/odb.h +44 -20
  84. data/vendor/libgit2/include/git2/oidarray.h +5 -8
  85. data/vendor/libgit2/include/git2/pack.h +1 -1
  86. data/vendor/libgit2/include/git2/patch.h +8 -0
  87. data/vendor/libgit2/include/git2/rebase.h +25 -1
  88. data/vendor/libgit2/include/git2/refs.h +9 -5
  89. data/vendor/libgit2/include/git2/remote.h +62 -9
  90. data/vendor/libgit2/include/git2/repository.h +107 -62
  91. data/vendor/libgit2/include/git2/revparse.h +5 -5
  92. data/vendor/libgit2/include/git2/stash.h +1 -1
  93. data/vendor/libgit2/include/git2/status.h +115 -59
  94. data/vendor/libgit2/include/git2/stdint.h +3 -3
  95. data/vendor/libgit2/include/git2/strarray.h +6 -10
  96. data/vendor/libgit2/include/git2/submodule.h +9 -0
  97. data/vendor/libgit2/include/git2/sys/commit_graph.h +174 -0
  98. data/vendor/libgit2/include/git2/sys/email.h +45 -0
  99. data/vendor/libgit2/include/git2/sys/filter.h +49 -28
  100. data/vendor/libgit2/include/git2/sys/midx.h +74 -0
  101. data/vendor/libgit2/include/git2/sys/odb_backend.h +7 -0
  102. data/vendor/libgit2/include/git2/sys/transport.h +1 -0
  103. data/vendor/libgit2/include/git2/tag.h +12 -0
  104. data/vendor/libgit2/include/git2/transport.h +1 -1
  105. data/vendor/libgit2/include/git2/tree.h +2 -14
  106. data/vendor/libgit2/include/git2/types.h +9 -0
  107. data/vendor/libgit2/include/git2/version.h +4 -4
  108. data/vendor/libgit2/include/git2/worktree.h +1 -0
  109. data/vendor/libgit2/include/git2.h +1 -0
  110. data/vendor/libgit2/src/CMakeLists.txt +84 -44
  111. data/vendor/libgit2/src/alloc.c +21 -8
  112. data/vendor/libgit2/src/allocators/failalloc.c +92 -0
  113. data/vendor/libgit2/src/allocators/failalloc.h +23 -0
  114. data/vendor/libgit2/src/allocators/stdalloc.c +41 -10
  115. data/vendor/libgit2/src/allocators/win32_leakcheck.c +118 -0
  116. data/vendor/libgit2/src/allocators/{win32_crtdbg.h → win32_leakcheck.h} +3 -3
  117. data/vendor/libgit2/src/annotated_commit.c +21 -9
  118. data/vendor/libgit2/src/apply.c +21 -8
  119. data/vendor/libgit2/src/array.h +11 -11
  120. data/vendor/libgit2/src/assert_safe.h +58 -0
  121. data/vendor/libgit2/src/attr.c +192 -70
  122. data/vendor/libgit2/src/attr_file.c +99 -41
  123. data/vendor/libgit2/src/attr_file.h +32 -11
  124. data/vendor/libgit2/src/attrcache.c +44 -40
  125. data/vendor/libgit2/src/attrcache.h +4 -5
  126. data/vendor/libgit2/src/blame.c +32 -19
  127. data/vendor/libgit2/src/blame_git.c +7 -4
  128. data/vendor/libgit2/src/blob.c +60 -32
  129. data/vendor/libgit2/src/branch.c +87 -37
  130. data/vendor/libgit2/src/buffer.c +349 -29
  131. data/vendor/libgit2/src/buffer.h +154 -2
  132. data/vendor/libgit2/src/cache.c +3 -24
  133. data/vendor/libgit2/src/cache.h +7 -7
  134. data/vendor/libgit2/src/cc-compat.h +10 -8
  135. data/vendor/libgit2/src/checkout.c +103 -105
  136. data/vendor/libgit2/src/cherrypick.c +8 -2
  137. data/vendor/libgit2/src/clone.c +105 -30
  138. data/vendor/libgit2/src/commit.c +41 -28
  139. data/vendor/libgit2/src/commit_graph.c +1209 -0
  140. data/vendor/libgit2/src/commit_graph.h +162 -0
  141. data/vendor/libgit2/src/commit_list.c +46 -0
  142. data/vendor/libgit2/src/commit_list.h +2 -0
  143. data/vendor/libgit2/src/common.h +26 -2
  144. data/vendor/libgit2/src/config.c +41 -23
  145. data/vendor/libgit2/src/config_cache.c +9 -4
  146. data/vendor/libgit2/src/config_entries.c +35 -27
  147. data/vendor/libgit2/src/config_file.c +17 -9
  148. data/vendor/libgit2/src/config_parse.c +6 -8
  149. data/vendor/libgit2/src/config_snapshot.c +2 -1
  150. data/vendor/libgit2/src/crlf.c +16 -6
  151. data/vendor/libgit2/src/date.c +4 -3
  152. data/vendor/libgit2/src/delta.c +1 -1
  153. data/vendor/libgit2/src/describe.c +12 -5
  154. data/vendor/libgit2/src/diff.c +55 -183
  155. data/vendor/libgit2/src/diff_driver.c +21 -17
  156. data/vendor/libgit2/src/diff_file.c +5 -7
  157. data/vendor/libgit2/src/diff_generate.c +56 -28
  158. data/vendor/libgit2/src/diff_parse.c +2 -3
  159. data/vendor/libgit2/src/diff_print.c +81 -65
  160. data/vendor/libgit2/src/diff_stats.c +19 -16
  161. data/vendor/libgit2/src/diff_tform.c +13 -13
  162. data/vendor/libgit2/src/diff_xdiff.c +4 -2
  163. data/vendor/libgit2/src/diff_xdiff.h +1 -1
  164. data/vendor/libgit2/src/email.c +299 -0
  165. data/vendor/libgit2/src/email.h +25 -0
  166. data/vendor/libgit2/src/errors.c +26 -19
  167. data/vendor/libgit2/src/features.h.in +5 -1
  168. data/vendor/libgit2/src/fetch.c +7 -2
  169. data/vendor/libgit2/src/fetchhead.c +8 -4
  170. data/vendor/libgit2/src/filebuf.c +9 -7
  171. data/vendor/libgit2/src/filter.c +215 -113
  172. data/vendor/libgit2/src/filter.h +24 -5
  173. data/vendor/libgit2/src/futils.c +8 -8
  174. data/vendor/libgit2/src/futils.h +4 -4
  175. data/vendor/libgit2/src/graph.c +64 -9
  176. data/vendor/libgit2/src/hash/sha1/collisiondetect.c +3 -3
  177. data/vendor/libgit2/src/hash/sha1/common_crypto.c +3 -3
  178. data/vendor/libgit2/src/hash/sha1/generic.h +1 -1
  179. data/vendor/libgit2/src/hash/sha1/mbedtls.c +12 -12
  180. data/vendor/libgit2/src/hash/sha1/openssl.c +3 -3
  181. data/vendor/libgit2/src/hash/sha1/sha1dc/sha1.c +8 -10
  182. data/vendor/libgit2/src/hash/sha1/win32.c +15 -11
  183. data/vendor/libgit2/src/hash.c +16 -13
  184. data/vendor/libgit2/src/hash.h +1 -1
  185. data/vendor/libgit2/src/hashsig.c +23 -10
  186. data/vendor/libgit2/src/ident.c +13 -3
  187. data/vendor/libgit2/src/idxmap.c +0 -22
  188. data/vendor/libgit2/src/ignore.c +33 -17
  189. data/vendor/libgit2/src/index.c +124 -82
  190. data/vendor/libgit2/src/index.h +1 -1
  191. data/vendor/libgit2/src/indexer.c +95 -37
  192. data/vendor/libgit2/src/integer.h +79 -2
  193. data/vendor/libgit2/src/iterator.c +40 -28
  194. data/vendor/libgit2/src/iterator.h +1 -1
  195. data/vendor/libgit2/src/khash.h +2 -11
  196. data/vendor/libgit2/src/{settings.c → libgit2.c} +148 -49
  197. data/vendor/libgit2/src/libgit2.h +15 -0
  198. data/vendor/libgit2/src/mailmap.c +23 -10
  199. data/vendor/libgit2/src/map.h +3 -3
  200. data/vendor/libgit2/src/merge.c +95 -43
  201. data/vendor/libgit2/src/merge.h +2 -1
  202. data/vendor/libgit2/src/merge_driver.c +19 -13
  203. data/vendor/libgit2/src/merge_file.c +15 -9
  204. data/vendor/libgit2/src/message.c +3 -1
  205. data/vendor/libgit2/src/midx.c +879 -0
  206. data/vendor/libgit2/src/midx.h +110 -0
  207. data/vendor/libgit2/src/mwindow.c +214 -95
  208. data/vendor/libgit2/src/mwindow.h +3 -3
  209. data/vendor/libgit2/src/net.c +133 -4
  210. data/vendor/libgit2/src/net.h +16 -2
  211. data/vendor/libgit2/src/netops.c +6 -4
  212. data/vendor/libgit2/src/netops.h +2 -2
  213. data/vendor/libgit2/src/notes.c +40 -40
  214. data/vendor/libgit2/src/object.c +24 -15
  215. data/vendor/libgit2/src/odb.c +298 -57
  216. data/vendor/libgit2/src/odb.h +16 -2
  217. data/vendor/libgit2/src/odb_loose.c +31 -21
  218. data/vendor/libgit2/src/odb_mempack.c +3 -1
  219. data/vendor/libgit2/src/odb_pack.c +391 -114
  220. data/vendor/libgit2/src/oid.c +7 -4
  221. data/vendor/libgit2/src/oidarray.c +10 -1
  222. data/vendor/libgit2/src/pack-objects.c +83 -69
  223. data/vendor/libgit2/src/pack.c +383 -150
  224. data/vendor/libgit2/src/pack.h +44 -9
  225. data/vendor/libgit2/src/patch.c +14 -7
  226. data/vendor/libgit2/src/patch_generate.c +3 -5
  227. data/vendor/libgit2/src/patch_parse.c +6 -3
  228. data/vendor/libgit2/src/path.c +103 -58
  229. data/vendor/libgit2/src/path.h +80 -7
  230. data/vendor/libgit2/src/pathspec.c +12 -11
  231. data/vendor/libgit2/src/pool.c +34 -22
  232. data/vendor/libgit2/src/pool.h +9 -1
  233. data/vendor/libgit2/src/posix.c +43 -12
  234. data/vendor/libgit2/src/posix.h +9 -0
  235. data/vendor/libgit2/src/proxy.c +2 -0
  236. data/vendor/libgit2/src/push.c +2 -0
  237. data/vendor/libgit2/src/reader.c +10 -6
  238. data/vendor/libgit2/src/rebase.c +95 -49
  239. data/vendor/libgit2/src/refdb.c +165 -13
  240. data/vendor/libgit2/src/refdb.h +69 -0
  241. data/vendor/libgit2/src/refdb_fs.c +145 -153
  242. data/vendor/libgit2/src/reflog.c +21 -20
  243. data/vendor/libgit2/src/refs.c +153 -233
  244. data/vendor/libgit2/src/refs.h +2 -20
  245. data/vendor/libgit2/src/refspec.c +81 -45
  246. data/vendor/libgit2/src/regexp.c +2 -2
  247. data/vendor/libgit2/src/remote.c +320 -122
  248. data/vendor/libgit2/src/remote.h +2 -1
  249. data/vendor/libgit2/src/repository.c +476 -203
  250. data/vendor/libgit2/src/repository.h +27 -29
  251. data/vendor/libgit2/src/reset.c +8 -7
  252. data/vendor/libgit2/src/revert.c +8 -2
  253. data/vendor/libgit2/src/revparse.c +23 -17
  254. data/vendor/libgit2/src/revwalk.c +35 -20
  255. data/vendor/libgit2/src/runtime.c +162 -0
  256. data/vendor/libgit2/src/runtime.h +62 -0
  257. data/vendor/libgit2/src/{refdb_fs.h → settings.h} +3 -11
  258. data/vendor/libgit2/src/signature.c +6 -5
  259. data/vendor/libgit2/src/sortedcache.c +2 -3
  260. data/vendor/libgit2/src/sortedcache.h +10 -8
  261. data/vendor/libgit2/src/stash.c +6 -2
  262. data/vendor/libgit2/src/status.c +9 -4
  263. data/vendor/libgit2/src/strarray.c +64 -0
  264. data/vendor/libgit2/src/streams/mbedtls.c +14 -17
  265. data/vendor/libgit2/src/streams/mbedtls.h +1 -1
  266. data/vendor/libgit2/src/streams/openssl.c +113 -207
  267. data/vendor/libgit2/src/streams/openssl.h +9 -1
  268. data/vendor/libgit2/src/streams/openssl_dynamic.c +309 -0
  269. data/vendor/libgit2/src/streams/openssl_dynamic.h +348 -0
  270. data/vendor/libgit2/src/streams/openssl_legacy.c +203 -0
  271. data/vendor/libgit2/src/streams/openssl_legacy.h +63 -0
  272. data/vendor/libgit2/src/streams/registry.c +10 -9
  273. data/vendor/libgit2/src/streams/socket.c +6 -2
  274. data/vendor/libgit2/src/streams/stransport.c +6 -3
  275. data/vendor/libgit2/src/streams/tls.c +5 -3
  276. data/vendor/libgit2/src/submodule.c +134 -66
  277. data/vendor/libgit2/src/submodule.h +9 -9
  278. data/vendor/libgit2/src/sysdir.c +8 -26
  279. data/vendor/libgit2/src/sysdir.h +0 -11
  280. data/vendor/libgit2/src/tag.c +49 -11
  281. data/vendor/libgit2/src/thread.c +140 -0
  282. data/vendor/libgit2/src/thread.h +479 -0
  283. data/vendor/libgit2/src/threadstate.c +84 -0
  284. data/vendor/libgit2/src/threadstate.h +24 -0
  285. data/vendor/libgit2/src/trace.c +2 -2
  286. data/vendor/libgit2/src/trace.h +17 -13
  287. data/vendor/libgit2/src/trailer.c +1 -1
  288. data/vendor/libgit2/src/transaction.c +21 -9
  289. data/vendor/libgit2/src/transport.c +3 -3
  290. data/vendor/libgit2/src/transports/auth.c +1 -1
  291. data/vendor/libgit2/src/transports/auth_negotiate.c +11 -4
  292. data/vendor/libgit2/src/transports/auth_ntlm.c +10 -6
  293. data/vendor/libgit2/src/transports/credential.c +17 -7
  294. data/vendor/libgit2/src/transports/credential_helpers.c +2 -0
  295. data/vendor/libgit2/src/transports/git.c +1 -3
  296. data/vendor/libgit2/src/transports/http.c +19 -17
  297. data/vendor/libgit2/src/transports/http.h +1 -0
  298. data/vendor/libgit2/src/transports/httpclient.c +68 -38
  299. data/vendor/libgit2/src/transports/httpclient.h +1 -1
  300. data/vendor/libgit2/src/transports/local.c +5 -5
  301. data/vendor/libgit2/src/transports/smart.c +14 -9
  302. data/vendor/libgit2/src/transports/smart.h +1 -1
  303. data/vendor/libgit2/src/transports/smart_protocol.c +11 -5
  304. data/vendor/libgit2/src/transports/ssh.c +55 -21
  305. data/vendor/libgit2/src/transports/winhttp.c +157 -89
  306. data/vendor/libgit2/src/tree.c +100 -77
  307. data/vendor/libgit2/src/tree.h +1 -0
  308. data/vendor/libgit2/src/tsort.c +0 -2
  309. data/vendor/libgit2/src/unix/map.c +3 -1
  310. data/vendor/libgit2/src/unix/posix.h +16 -1
  311. data/vendor/libgit2/src/unix/pthread.h +2 -1
  312. data/vendor/libgit2/src/utf8.c +150 -0
  313. data/vendor/libgit2/src/utf8.h +52 -0
  314. data/vendor/libgit2/src/util.c +75 -184
  315. data/vendor/libgit2/src/util.h +34 -40
  316. data/vendor/libgit2/src/vector.c +23 -19
  317. data/vendor/libgit2/src/vector.h +4 -2
  318. data/vendor/libgit2/src/win32/findfile.c +5 -3
  319. data/vendor/libgit2/src/win32/git2.rc +18 -3
  320. data/vendor/libgit2/src/win32/map.c +1 -1
  321. data/vendor/libgit2/src/win32/msvc-compat.h +9 -1
  322. data/vendor/libgit2/src/win32/path_w32.c +23 -25
  323. data/vendor/libgit2/src/win32/path_w32.h +0 -1
  324. data/vendor/libgit2/src/win32/posix.h +6 -6
  325. data/vendor/libgit2/src/win32/posix_w32.c +86 -7
  326. data/vendor/libgit2/src/win32/precompiled.h +0 -1
  327. data/vendor/libgit2/src/win32/reparse.h +4 -4
  328. data/vendor/libgit2/src/win32/thread.c +24 -15
  329. data/vendor/libgit2/src/win32/thread.h +1 -1
  330. data/vendor/libgit2/src/win32/w32_buffer.c +3 -3
  331. data/vendor/libgit2/src/win32/w32_common.h +18 -9
  332. data/vendor/libgit2/src/win32/{w32_crtdbg_stacktrace.c → w32_leakcheck.c} +269 -33
  333. data/vendor/libgit2/src/win32/w32_leakcheck.h +222 -0
  334. data/vendor/libgit2/src/win32/w32_util.h +6 -6
  335. data/vendor/libgit2/src/worktree.c +36 -14
  336. data/vendor/libgit2/src/zstream.c +1 -1
  337. metadata +65 -42
  338. data/vendor/libgit2/cmake/Modules/CheckPrototypeDefinition.c.in +0 -29
  339. data/vendor/libgit2/cmake/Modules/CheckPrototypeDefinition.cmake +0 -96
  340. data/vendor/libgit2/src/allocators/win32_crtdbg.c +0 -118
  341. data/vendor/libgit2/src/buf_text.c +0 -316
  342. data/vendor/libgit2/src/buf_text.h +0 -122
  343. data/vendor/libgit2/src/global.c +0 -361
  344. data/vendor/libgit2/src/global.h +0 -41
  345. data/vendor/libgit2/src/thread-utils.c +0 -58
  346. data/vendor/libgit2/src/thread-utils.h +0 -246
  347. data/vendor/libgit2/src/win32/w32_crtdbg_stacktrace.h +0 -127
  348. data/vendor/libgit2/src/win32/w32_stack.c +0 -188
  349. data/vendor/libgit2/src/win32/w32_stack.h +0 -140
@@ -62,16 +62,18 @@ static const struct {
62
62
  { GIT_REPOSITORY_ITEM_COMMONDIR, GIT_REPOSITORY_ITEM_GITDIR, "worktrees", true }
63
63
  };
64
64
 
65
- static int check_repositoryformatversion(git_config *config);
65
+ static int check_repositoryformatversion(int *version, git_config *config);
66
+ static int check_extensions(git_config *config, int version);
66
67
 
67
68
  #define GIT_COMMONDIR_FILE "commondir"
68
69
  #define GIT_GITDIR_FILE "gitdir"
69
70
 
70
71
  #define GIT_FILE_CONTENT_PREFIX "gitdir:"
71
72
 
72
- #define GIT_BRANCH_MASTER "master"
73
+ #define GIT_BRANCH_DEFAULT "master"
73
74
 
74
75
  #define GIT_REPO_VERSION 0
76
+ #define GIT_REPO_MAX_VERSION 1
75
77
 
76
78
  git_buf git_repository__reserved_names_win32[] = {
77
79
  { DOT_GIT, 0, CONST_STRLEN(DOT_GIT) },
@@ -91,7 +93,7 @@ static void set_odb(git_repository *repo, git_odb *odb)
91
93
  GIT_REFCOUNT_INC(odb);
92
94
  }
93
95
 
94
- if ((odb = git__swap(repo->_odb, odb)) != NULL) {
96
+ if ((odb = git_atomic_swap(repo->_odb, odb)) != NULL) {
95
97
  GIT_REFCOUNT_OWN(odb, NULL);
96
98
  git_odb_free(odb);
97
99
  }
@@ -104,7 +106,7 @@ static void set_refdb(git_repository *repo, git_refdb *refdb)
104
106
  GIT_REFCOUNT_INC(refdb);
105
107
  }
106
108
 
107
- if ((refdb = git__swap(repo->_refdb, refdb)) != NULL) {
109
+ if ((refdb = git_atomic_swap(repo->_refdb, refdb)) != NULL) {
108
110
  GIT_REFCOUNT_OWN(refdb, NULL);
109
111
  git_refdb_free(refdb);
110
112
  }
@@ -117,7 +119,7 @@ static void set_config(git_repository *repo, git_config *config)
117
119
  GIT_REFCOUNT_INC(config);
118
120
  }
119
121
 
120
- if ((config = git__swap(repo->_config, config)) != NULL) {
122
+ if ((config = git_atomic_swap(repo->_config, config)) != NULL) {
121
123
  GIT_REFCOUNT_OWN(config, NULL);
122
124
  git_config_free(config);
123
125
  }
@@ -132,7 +134,7 @@ static void set_index(git_repository *repo, git_index *index)
132
134
  GIT_REFCOUNT_INC(index);
133
135
  }
134
136
 
135
- if ((index = git__swap(repo->_index, index)) != NULL) {
137
+ if ((index = git_atomic_swap(repo->_index, index)) != NULL) {
136
138
  GIT_REFCOUNT_OWN(index, NULL);
137
139
  git_index_free(index);
138
140
  }
@@ -140,7 +142,7 @@ static void set_index(git_repository *repo, git_index *index)
140
142
 
141
143
  int git_repository__cleanup(git_repository *repo)
142
144
  {
143
- assert(repo);
145
+ GIT_ASSERT_ARG(repo);
144
146
 
145
147
  git_repository_submodule_cache_clear(repo);
146
148
  git_cache_clear(&repo->objects);
@@ -184,6 +186,63 @@ void git_repository_free(git_repository *repo)
184
186
  git__free(repo);
185
187
  }
186
188
 
189
+ /* Check if we have a separate commondir (e.g. we have a worktree) */
190
+ static int lookup_commondir(bool *separate, git_buf *commondir, git_buf *repository_path)
191
+ {
192
+ git_buf common_link = GIT_BUF_INIT;
193
+ int error;
194
+
195
+ /*
196
+ * If there's no commondir file, the repository path is the
197
+ * common path, but it needs a trailing slash.
198
+ */
199
+ if (!git_path_contains_file(repository_path, GIT_COMMONDIR_FILE)) {
200
+ if ((error = git_buf_set(commondir, repository_path->ptr, repository_path->size)) == 0)
201
+ error = git_path_to_dir(commondir);
202
+
203
+ *separate = false;
204
+ goto done;
205
+ }
206
+
207
+ *separate = true;
208
+
209
+ if ((error = git_buf_joinpath(&common_link, repository_path->ptr, GIT_COMMONDIR_FILE)) < 0 ||
210
+ (error = git_futils_readbuffer(&common_link, common_link.ptr)) < 0)
211
+ goto done;
212
+
213
+ git_buf_rtrim(&common_link);
214
+ if (git_path_is_relative(common_link.ptr)) {
215
+ if ((error = git_buf_joinpath(commondir, repository_path->ptr, common_link.ptr)) < 0)
216
+ goto done;
217
+ } else {
218
+ git_buf_swap(commondir, &common_link);
219
+ }
220
+
221
+ git_buf_dispose(&common_link);
222
+
223
+ /* Make sure the commondir path always has a trailing slash */
224
+ error = git_path_prettify_dir(commondir, commondir->ptr, NULL);
225
+
226
+ done:
227
+ return error;
228
+ }
229
+
230
+ GIT_INLINE(int) validate_repo_path(git_buf *path)
231
+ {
232
+ /*
233
+ * The longest static path in a repository (or commondir) is the
234
+ * packed refs file. (Loose refs may be longer since they
235
+ * include the reference name, but will be validated when the
236
+ * path is constructed.)
237
+ */
238
+ static size_t suffix_len =
239
+ CONST_STRLEN("objects/pack/pack-.pack.lock") +
240
+ GIT_OID_HEXSZ;
241
+
242
+ return git_path_validate_filesystem_with_suffix(
243
+ path->ptr, path->size, suffix_len);
244
+ }
245
+
187
246
  /*
188
247
  * Git repository open methods
189
248
  *
@@ -191,48 +250,30 @@ void git_repository_free(git_repository *repo)
191
250
  */
192
251
  static int is_valid_repository_path(bool *out, git_buf *repository_path, git_buf *common_path)
193
252
  {
253
+ bool separate_commondir = false;
194
254
  int error;
195
255
 
196
256
  *out = false;
197
257
 
198
- /* Check if we have a separate commondir (e.g. we have a
199
- * worktree) */
200
- if (git_path_contains_file(repository_path, GIT_COMMONDIR_FILE)) {
201
- git_buf common_link = GIT_BUF_INIT;
202
-
203
- if ((error = git_buf_joinpath(&common_link, repository_path->ptr, GIT_COMMONDIR_FILE)) < 0 ||
204
- (error = git_futils_readbuffer(&common_link, common_link.ptr)) < 0)
205
- return error;
206
-
207
- git_buf_rtrim(&common_link);
208
- if (git_path_is_relative(common_link.ptr)) {
209
- if ((error = git_buf_joinpath(common_path, repository_path->ptr, common_link.ptr)) < 0)
210
- return error;
211
- } else {
212
- git_buf_swap(common_path, &common_link);
213
- }
214
-
215
- git_buf_dispose(&common_link);
216
- }
217
- else {
218
- if ((error = git_buf_set(common_path, repository_path->ptr, repository_path->size)) < 0)
219
- return error;
220
- }
221
-
222
- /* Make sure the commondir path always has a trailing * slash */
223
- if (git_buf_rfind(common_path, '/') != (ssize_t)common_path->size - 1)
224
- if ((error = git_buf_putc(common_path, '/')) < 0)
225
- return error;
258
+ if ((error = lookup_commondir(&separate_commondir, common_path, repository_path)) < 0)
259
+ return error;
226
260
 
227
261
  /* Ensure HEAD file exists */
228
262
  if (git_path_contains_file(repository_path, GIT_HEAD_FILE) == false)
229
263
  return 0;
264
+
230
265
  /* Check files in common dir */
231
266
  if (git_path_contains_dir(common_path, GIT_OBJECTS_DIR) == false)
232
267
  return 0;
233
268
  if (git_path_contains_dir(common_path, GIT_REFS_DIR) == false)
234
269
  return 0;
235
270
 
271
+ /* Ensure the repo (and commondir) are valid paths */
272
+ if ((error = validate_repo_path(common_path)) < 0 ||
273
+ (separate_commondir &&
274
+ (error = validate_repo_path(repository_path)) < 0))
275
+ return error;
276
+
236
277
  *out = true;
237
278
  return 0;
238
279
  }
@@ -366,7 +407,7 @@ static size_t find_ceiling_dir_offset(
366
407
  const char *ceil, *sep;
367
408
  size_t len, max_len = 0, min_len;
368
409
 
369
- assert(path);
410
+ GIT_ASSERT_ARG(path);
370
411
 
371
412
  min_len = (size_t)(git_path_root(path) + 1);
372
413
 
@@ -412,7 +453,8 @@ static int read_gitfile(git_buf *path_out, const char *file_path)
412
453
  git_buf file = GIT_BUF_INIT;
413
454
  size_t prefix_len = strlen(GIT_FILE_CONTENT_PREFIX);
414
455
 
415
- assert(path_out && file_path);
456
+ GIT_ASSERT_ARG(path_out);
457
+ GIT_ASSERT_ARG(file_path);
416
458
 
417
459
  if (git_futils_readbuffer(&file, file_path) < 0)
418
460
  return -1;
@@ -813,6 +855,7 @@ int git_repository_open_ext(
813
855
  gitlink = GIT_BUF_INIT, commondir = GIT_BUF_INIT;
814
856
  git_repository *repo = NULL;
815
857
  git_config *config = NULL;
858
+ int version = 0;
816
859
 
817
860
  if (flags & GIT_REPOSITORY_OPEN_FROM_ENV)
818
861
  return _git_repository_open_ext_from_env(repo_ptr, start_path);
@@ -854,7 +897,10 @@ int git_repository_open_ext(
854
897
  if (error < 0 && error != GIT_ENOTFOUND)
855
898
  goto cleanup;
856
899
 
857
- if (config && (error = check_repositoryformatversion(config)) < 0)
900
+ if (config && (error = check_repositoryformatversion(&version, config)) < 0)
901
+ goto cleanup;
902
+
903
+ if ((error = check_extensions(config, version)) < 0)
858
904
  goto cleanup;
859
905
 
860
906
  if ((flags & GIT_REPOSITORY_OPEN_BARE) != 0)
@@ -895,7 +941,8 @@ int git_repository_open_from_worktree(git_repository **repo_out, git_worktree *w
895
941
  size_t len;
896
942
  int err;
897
943
 
898
- assert(repo_out && wt);
944
+ GIT_ASSERT_ARG(repo_out);
945
+ GIT_ASSERT_ARG(wt);
899
946
 
900
947
  *repo_out = NULL;
901
948
  len = strlen(wt->gitlink_path);
@@ -939,10 +986,12 @@ int git_repository_discover(
939
986
  const char *ceiling_dirs)
940
987
  {
941
988
  uint32_t flags = across_fs ? GIT_REPOSITORY_OPEN_CROSS_FS : 0;
989
+ int error;
942
990
 
943
- assert(start_path);
991
+ GIT_ASSERT_ARG(start_path);
944
992
 
945
- git_buf_sanitize(out);
993
+ if ((error = git_buf_sanitize(out)) < 0)
994
+ return error;
946
995
 
947
996
  return find_repo(out, NULL, NULL, NULL, start_path, flags, ceiling_dirs);
948
997
  }
@@ -959,7 +1008,7 @@ static int load_config(
959
1008
  git_buf config_path = GIT_BUF_INIT;
960
1009
  git_config *cfg = NULL;
961
1010
 
962
- assert(out);
1011
+ GIT_ASSERT_ARG(out);
963
1012
 
964
1013
  if ((error = git_config_new(&cfg)) < 0)
965
1014
  return error;
@@ -1044,8 +1093,7 @@ int git_repository_config__weakptr(git_config **out, git_repository *repo)
1044
1093
  if (!error) {
1045
1094
  GIT_REFCOUNT_OWN(config, repo);
1046
1095
 
1047
- config = git__compare_and_swap(&repo->_config, NULL, config);
1048
- if (config != NULL) {
1096
+ if (git_atomic_compare_and_swap(&repo->_config, NULL, config) != NULL) {
1049
1097
  GIT_REFCOUNT_OWN(config, NULL);
1050
1098
  git_config_free(config);
1051
1099
  }
@@ -1083,7 +1131,9 @@ int git_repository_config_snapshot(git_config **out, git_repository *repo)
1083
1131
 
1084
1132
  int git_repository_set_config(git_repository *repo, git_config *config)
1085
1133
  {
1086
- assert(repo && config);
1134
+ GIT_ASSERT_ARG(repo);
1135
+ GIT_ASSERT_ARG(config);
1136
+
1087
1137
  set_config(repo, config);
1088
1138
  return 0;
1089
1139
  }
@@ -1092,9 +1142,11 @@ int git_repository_odb__weakptr(git_odb **out, git_repository *repo)
1092
1142
  {
1093
1143
  int error = 0;
1094
1144
 
1095
- assert(repo && out);
1145
+ GIT_ASSERT_ARG(repo);
1146
+ GIT_ASSERT_ARG(out);
1096
1147
 
1097
- if (repo->_odb == NULL) {
1148
+ *out = git_atomic_load(repo->_odb);
1149
+ if (*out == NULL) {
1098
1150
  git_buf odb_path = GIT_BUF_INIT;
1099
1151
  git_odb *odb;
1100
1152
 
@@ -1111,16 +1163,15 @@ int git_repository_odb__weakptr(git_odb **out, git_repository *repo)
1111
1163
  return error;
1112
1164
  }
1113
1165
 
1114
- odb = git__compare_and_swap(&repo->_odb, NULL, odb);
1115
- if (odb != NULL) {
1166
+ if (git_atomic_compare_and_swap(&repo->_odb, NULL, odb) != NULL) {
1116
1167
  GIT_REFCOUNT_OWN(odb, NULL);
1117
1168
  git_odb_free(odb);
1118
1169
  }
1119
1170
 
1120
1171
  git_buf_dispose(&odb_path);
1172
+ *out = git_atomic_load(repo->_odb);
1121
1173
  }
1122
1174
 
1123
- *out = repo->_odb;
1124
1175
  return error;
1125
1176
  }
1126
1177
 
@@ -1135,7 +1186,9 @@ int git_repository_odb(git_odb **out, git_repository *repo)
1135
1186
 
1136
1187
  int git_repository_set_odb(git_repository *repo, git_odb *odb)
1137
1188
  {
1138
- assert(repo && odb);
1189
+ GIT_ASSERT_ARG(repo);
1190
+ GIT_ASSERT_ARG(odb);
1191
+
1139
1192
  set_odb(repo, odb);
1140
1193
  return 0;
1141
1194
  }
@@ -1144,7 +1197,8 @@ int git_repository_refdb__weakptr(git_refdb **out, git_repository *repo)
1144
1197
  {
1145
1198
  int error = 0;
1146
1199
 
1147
- assert(out && repo);
1200
+ GIT_ASSERT_ARG(out);
1201
+ GIT_ASSERT_ARG(repo);
1148
1202
 
1149
1203
  if (repo->_refdb == NULL) {
1150
1204
  git_refdb *refdb;
@@ -1153,8 +1207,7 @@ int git_repository_refdb__weakptr(git_refdb **out, git_repository *repo)
1153
1207
  if (!error) {
1154
1208
  GIT_REFCOUNT_OWN(refdb, repo);
1155
1209
 
1156
- refdb = git__compare_and_swap(&repo->_refdb, NULL, refdb);
1157
- if (refdb != NULL) {
1210
+ if (git_atomic_compare_and_swap(&repo->_refdb, NULL, refdb) != NULL) {
1158
1211
  GIT_REFCOUNT_OWN(refdb, NULL);
1159
1212
  git_refdb_free(refdb);
1160
1213
  }
@@ -1176,7 +1229,9 @@ int git_repository_refdb(git_refdb **out, git_repository *repo)
1176
1229
 
1177
1230
  int git_repository_set_refdb(git_repository *repo, git_refdb *refdb)
1178
1231
  {
1179
- assert(repo && refdb);
1232
+ GIT_ASSERT_ARG(repo);
1233
+ GIT_ASSERT_ARG(refdb);
1234
+
1180
1235
  set_refdb(repo, refdb);
1181
1236
  return 0;
1182
1237
  }
@@ -1185,7 +1240,8 @@ int git_repository_index__weakptr(git_index **out, git_repository *repo)
1185
1240
  {
1186
1241
  int error = 0;
1187
1242
 
1188
- assert(out && repo);
1243
+ GIT_ASSERT_ARG(out);
1244
+ GIT_ASSERT_ARG(repo);
1189
1245
 
1190
1246
  if (repo->_index == NULL) {
1191
1247
  git_buf index_path = GIT_BUF_INIT;
@@ -1198,8 +1254,7 @@ int git_repository_index__weakptr(git_index **out, git_repository *repo)
1198
1254
  if (!error) {
1199
1255
  GIT_REFCOUNT_OWN(index, repo);
1200
1256
 
1201
- index = git__compare_and_swap(&repo->_index, NULL, index);
1202
- if (index != NULL) {
1257
+ if (git_atomic_compare_and_swap(&repo->_index, NULL, index) != NULL) {
1203
1258
  GIT_REFCOUNT_OWN(index, NULL);
1204
1259
  git_index_free(index);
1205
1260
  }
@@ -1226,7 +1281,7 @@ int git_repository_index(git_index **out, git_repository *repo)
1226
1281
 
1227
1282
  int git_repository_set_index(git_repository *repo, git_index *index)
1228
1283
  {
1229
- assert(repo);
1284
+ GIT_ASSERT_ARG(repo);
1230
1285
  set_index(repo, index);
1231
1286
  return 0;
1232
1287
  }
@@ -1350,11 +1405,11 @@ bool git_repository__reserved_names(
1350
1405
  }
1351
1406
  #endif
1352
1407
 
1353
- static int check_repositoryformatversion(git_config *config)
1408
+ static int check_repositoryformatversion(int *version, git_config *config)
1354
1409
  {
1355
- int version, error;
1410
+ int error;
1356
1411
 
1357
- error = git_config_get_int32(&version, config, "core.repositoryformatversion");
1412
+ error = git_config_get_int32(version, config, "core.repositoryformatversion");
1358
1413
  /* git ignores this if the config variable isn't there */
1359
1414
  if (error == GIT_ENOTFOUND)
1360
1415
  return 0;
@@ -1362,16 +1417,144 @@ static int check_repositoryformatversion(git_config *config)
1362
1417
  if (error < 0)
1363
1418
  return -1;
1364
1419
 
1365
- if (GIT_REPO_VERSION < version) {
1420
+ if (GIT_REPO_MAX_VERSION < *version) {
1366
1421
  git_error_set(GIT_ERROR_REPOSITORY,
1367
- "unsupported repository version %d. Only versions up to %d are supported.",
1368
- version, GIT_REPO_VERSION);
1422
+ "unsupported repository version %d; only versions up to %d are supported",
1423
+ *version, GIT_REPO_MAX_VERSION);
1424
+ return -1;
1425
+ }
1426
+
1427
+ return 0;
1428
+ }
1429
+
1430
+ static const char *builtin_extensions[] = {
1431
+ "noop"
1432
+ };
1433
+
1434
+ static git_vector user_extensions = GIT_VECTOR_INIT;
1435
+
1436
+ static int check_valid_extension(const git_config_entry *entry, void *payload)
1437
+ {
1438
+ git_buf cfg = GIT_BUF_INIT;
1439
+ bool reject;
1440
+ const char *extension;
1441
+ size_t i;
1442
+ int error = 0;
1443
+
1444
+ GIT_UNUSED(payload);
1445
+
1446
+ git_vector_foreach (&user_extensions, i, extension) {
1447
+ git_buf_clear(&cfg);
1448
+
1449
+ /*
1450
+ * Users can specify that they don't want to support an
1451
+ * extension with a '!' prefix.
1452
+ */
1453
+ if ((reject = (extension[0] == '!')) == true)
1454
+ extension = &extension[1];
1455
+
1456
+ if ((error = git_buf_printf(&cfg, "extensions.%s", extension)) < 0)
1457
+ goto done;
1458
+
1459
+ if (strcmp(entry->name, cfg.ptr) == 0) {
1460
+ if (reject)
1461
+ goto fail;
1462
+
1463
+ goto done;
1464
+ }
1465
+ }
1466
+
1467
+ for (i = 0; i < ARRAY_SIZE(builtin_extensions); i++) {
1468
+ extension = builtin_extensions[i];
1469
+
1470
+ if ((error = git_buf_printf(&cfg, "extensions.%s", extension)) < 0)
1471
+ goto done;
1472
+
1473
+ if (strcmp(entry->name, cfg.ptr) == 0)
1474
+ goto done;
1475
+ }
1476
+
1477
+ fail:
1478
+ git_error_set(GIT_ERROR_REPOSITORY, "unsupported extension name %s", entry->name);
1479
+ error = -1;
1480
+
1481
+ done:
1482
+ git_buf_dispose(&cfg);
1483
+ return error;
1484
+ }
1485
+
1486
+ static int check_extensions(git_config *config, int version)
1487
+ {
1488
+ if (version < 1)
1489
+ return 0;
1490
+
1491
+ return git_config_foreach_match(config, "^extensions\\.", check_valid_extension, NULL);
1492
+ }
1493
+
1494
+ int git_repository__extensions(char ***out, size_t *out_len)
1495
+ {
1496
+ git_vector extensions;
1497
+ const char *builtin, *user;
1498
+ char *extension;
1499
+ size_t i, j;
1500
+
1501
+ if (git_vector_init(&extensions, 8, NULL) < 0)
1369
1502
  return -1;
1503
+
1504
+ for (i = 0; i < ARRAY_SIZE(builtin_extensions); i++) {
1505
+ bool match = false;
1506
+
1507
+ builtin = builtin_extensions[i];
1508
+
1509
+ git_vector_foreach (&user_extensions, j, user) {
1510
+ if (user[0] == '!' && strcmp(builtin, &user[1]) == 0) {
1511
+ match = true;
1512
+ break;
1513
+ }
1514
+ }
1515
+
1516
+ if (match)
1517
+ continue;
1518
+
1519
+ if ((extension = git__strdup(builtin)) == NULL ||
1520
+ git_vector_insert(&extensions, extension) < 0)
1521
+ return -1;
1522
+ }
1523
+
1524
+ git_vector_foreach (&user_extensions, i, user) {
1525
+ if (user[0] == '!')
1526
+ continue;
1527
+
1528
+ if ((extension = git__strdup(user)) == NULL ||
1529
+ git_vector_insert(&extensions, extension) < 0)
1530
+ return -1;
1370
1531
  }
1371
1532
 
1533
+ *out = (char **)git_vector_detach(out_len, NULL, &extensions);
1372
1534
  return 0;
1373
1535
  }
1374
1536
 
1537
+ int git_repository__set_extensions(const char **extensions, size_t len)
1538
+ {
1539
+ char *extension;
1540
+ size_t i;
1541
+
1542
+ git_repository__free_extensions();
1543
+
1544
+ for (i = 0; i < len; i++) {
1545
+ if ((extension = git__strdup(extensions[i])) == NULL ||
1546
+ git_vector_insert(&user_extensions, extension) < 0)
1547
+ return -1;
1548
+ }
1549
+
1550
+ return 0;
1551
+ }
1552
+
1553
+ void git_repository__free_extensions(void)
1554
+ {
1555
+ git_vector_free_deep(&user_extensions);
1556
+ }
1557
+
1375
1558
  int git_repository_create_head(const char *git_dir, const char *ref_name)
1376
1559
  {
1377
1560
  git_buf ref_path = GIT_BUF_INIT;
@@ -1383,9 +1566,6 @@ int git_repository_create_head(const char *git_dir, const char *ref_name)
1383
1566
  (error = git_filebuf_open(&ref, ref_path.ptr, 0, GIT_REFS_FILE_MODE)) < 0)
1384
1567
  goto out;
1385
1568
 
1386
- if (!ref_name)
1387
- ref_name = GIT_BRANCH_MASTER;
1388
-
1389
1569
  if (git__prefixcmp(ref_name, GIT_REFS_DIR) == 0)
1390
1570
  fmt = "ref: %s\n";
1391
1571
  else
@@ -1583,11 +1763,15 @@ static int repo_init_config(
1583
1763
  git_config *config = NULL;
1584
1764
  bool is_bare = ((flags & GIT_REPOSITORY_INIT_BARE) != 0);
1585
1765
  bool is_reinit = ((flags & GIT_REPOSITORY_INIT__IS_REINIT) != 0);
1766
+ int version = 0;
1586
1767
 
1587
1768
  if ((error = repo_local_config(&config, &cfg_path, NULL, repo_dir)) < 0)
1588
1769
  goto cleanup;
1589
1770
 
1590
- if (is_reinit && (error = check_repositoryformatversion(config)) < 0)
1771
+ if (is_reinit && (error = check_repositoryformatversion(&version, config)) < 0)
1772
+ goto cleanup;
1773
+
1774
+ if ((error = check_extensions(config, version)) < 0)
1591
1775
  goto cleanup;
1592
1776
 
1593
1777
  #define SET_REPO_CONFIG(TYPE, NAME, VAL) do { \
@@ -2032,6 +2216,44 @@ static int repo_init_directories(
2032
2216
  return error;
2033
2217
  }
2034
2218
 
2219
+ static int repo_init_head(const char *repo_dir, const char *given)
2220
+ {
2221
+ git_config *cfg = NULL;
2222
+ git_buf head_path = GIT_BUF_INIT, cfg_branch = GIT_BUF_INIT;
2223
+ const char *initial_head = NULL;
2224
+ int error;
2225
+
2226
+ if ((error = git_buf_joinpath(&head_path, repo_dir, GIT_HEAD_FILE)) < 0)
2227
+ goto out;
2228
+
2229
+ /*
2230
+ * A template may have set a HEAD; use that unless it's been
2231
+ * overridden by the caller's given initial head setting.
2232
+ */
2233
+ if (git_path_exists(head_path.ptr) && !given)
2234
+ goto out;
2235
+
2236
+ if (given) {
2237
+ initial_head = given;
2238
+ } else if ((error = git_config_open_default(&cfg)) >= 0 &&
2239
+ (error = git_config_get_string_buf(&cfg_branch, cfg, "init.defaultbranch")) >= 0 &&
2240
+ *cfg_branch.ptr) {
2241
+ initial_head = cfg_branch.ptr;
2242
+ }
2243
+
2244
+ if (!initial_head)
2245
+ initial_head = GIT_BRANCH_DEFAULT;
2246
+
2247
+ error = git_repository_create_head(repo_dir, initial_head);
2248
+
2249
+ out:
2250
+ git_config_free(cfg);
2251
+ git_buf_dispose(&head_path);
2252
+ git_buf_dispose(&cfg_branch);
2253
+
2254
+ return error;
2255
+ }
2256
+
2035
2257
  static int repo_init_create_origin(git_repository *repo, const char *url)
2036
2258
  {
2037
2259
  int error;
@@ -2062,12 +2284,14 @@ int git_repository_init_ext(
2062
2284
  git_repository_init_options *opts)
2063
2285
  {
2064
2286
  git_buf repo_path = GIT_BUF_INIT, wd_path = GIT_BUF_INIT,
2065
- common_path = GIT_BUF_INIT, head_path = GIT_BUF_INIT;
2287
+ common_path = GIT_BUF_INIT;
2066
2288
  const char *wd;
2067
2289
  bool is_valid;
2068
2290
  int error;
2069
2291
 
2070
- assert(out && given_repo && opts);
2292
+ GIT_ASSERT_ARG(out);
2293
+ GIT_ASSERT_ARG(given_repo);
2294
+ GIT_ASSERT_ARG(opts);
2071
2295
 
2072
2296
  GIT_ERROR_CHECK_VERSION(opts, GIT_REPOSITORY_INIT_OPTIONS_VERSION, "git_repository_init_options");
2073
2297
 
@@ -2096,16 +2320,7 @@ int git_repository_init_ext(
2096
2320
  } else {
2097
2321
  if ((error = repo_init_structure(repo_path.ptr, wd, opts)) < 0 ||
2098
2322
  (error = repo_init_config(repo_path.ptr, wd, opts->flags, opts->mode)) < 0 ||
2099
- (error = git_buf_joinpath(&head_path, repo_path.ptr, GIT_HEAD_FILE)) < 0)
2100
- goto out;
2101
-
2102
- /*
2103
- * Only set the new HEAD if the file does not exist already via
2104
- * a template or if the caller has explicitly supplied an
2105
- * initial HEAD value.
2106
- */
2107
- if ((!git_path_exists(head_path.ptr) || opts->initial_head) &&
2108
- (error = git_repository_create_head(repo_path.ptr, opts->initial_head)) < 0)
2323
+ (error = repo_init_head(repo_path.ptr, opts->initial_head)) < 0)
2109
2324
  goto out;
2110
2325
  }
2111
2326
 
@@ -2117,7 +2332,6 @@ int git_repository_init_ext(
2117
2332
  goto out;
2118
2333
 
2119
2334
  out:
2120
- git_buf_dispose(&head_path);
2121
2335
  git_buf_dispose(&common_path);
2122
2336
  git_buf_dispose(&repo_path);
2123
2337
  git_buf_dispose(&wd_path);
@@ -2148,18 +2362,13 @@ int git_repository_head_detached(git_repository *repo)
2148
2362
  return exists;
2149
2363
  }
2150
2364
 
2151
- static int get_worktree_file_path(git_buf *out, git_repository *repo, const char *worktree, const char *file)
2152
- {
2153
- git_buf_clear(out);
2154
- return git_buf_printf(out, "%s/worktrees/%s/%s", repo->commondir, worktree, file);
2155
- }
2156
-
2157
2365
  int git_repository_head_detached_for_worktree(git_repository *repo, const char *name)
2158
2366
  {
2159
2367
  git_reference *ref = NULL;
2160
2368
  int error;
2161
2369
 
2162
- assert(repo && name);
2370
+ GIT_ASSERT_ARG(repo);
2371
+ GIT_ASSERT_ARG(name);
2163
2372
 
2164
2373
  if ((error = git_repository_head_for_worktree(&ref, repo, name)) < 0)
2165
2374
  goto out;
@@ -2176,7 +2385,7 @@ int git_repository_head(git_reference **head_out, git_repository *repo)
2176
2385
  git_reference *head;
2177
2386
  int error;
2178
2387
 
2179
- assert(head_out);
2388
+ GIT_ASSERT_ARG(head_out);
2180
2389
 
2181
2390
  if ((error = git_reference_lookup(&head, repo, GIT_HEAD_FILE)) < 0)
2182
2391
  return error;
@@ -2194,73 +2403,85 @@ int git_repository_head(git_reference **head_out, git_repository *repo)
2194
2403
 
2195
2404
  int git_repository_head_for_worktree(git_reference **out, git_repository *repo, const char *name)
2196
2405
  {
2197
- git_buf path = GIT_BUF_INIT;
2406
+ git_repository *worktree_repo = NULL;
2407
+ git_worktree *worktree = NULL;
2198
2408
  git_reference *head = NULL;
2199
2409
  int error;
2200
2410
 
2201
- assert(out && repo && name);
2411
+ GIT_ASSERT_ARG(out);
2412
+ GIT_ASSERT_ARG(repo);
2413
+ GIT_ASSERT_ARG(name);
2202
2414
 
2203
2415
  *out = NULL;
2204
2416
 
2205
- if ((error = get_worktree_file_path(&path, repo, name, GIT_HEAD_FILE)) < 0 ||
2206
- (error = git_reference__read_head(&head, repo, path.ptr)) < 0)
2417
+ if ((error = git_worktree_lookup(&worktree, repo, name)) < 0 ||
2418
+ (error = git_repository_open_from_worktree(&worktree_repo, worktree)) < 0 ||
2419
+ (error = git_reference_lookup(&head, worktree_repo, GIT_HEAD_FILE)) < 0)
2207
2420
  goto out;
2208
2421
 
2209
2422
  if (git_reference_type(head) != GIT_REFERENCE_DIRECT) {
2210
- git_reference *resolved;
2211
-
2212
- error = git_reference_lookup_resolved(&resolved, repo, git_reference_symbolic_target(head), -1);
2213
- git_reference_free(head);
2214
- head = resolved;
2423
+ if ((error = git_reference_lookup_resolved(out, worktree_repo, git_reference_symbolic_target(head), -1)) < 0)
2424
+ goto out;
2425
+ } else {
2426
+ *out = head;
2427
+ head = NULL;
2215
2428
  }
2216
2429
 
2217
- *out = head;
2218
-
2219
2430
  out:
2220
- if (error)
2221
- git_reference_free(head);
2222
-
2223
- git_buf_dispose(&path);
2224
-
2431
+ git_reference_free(head);
2432
+ git_worktree_free(worktree);
2433
+ git_repository_free(worktree_repo);
2225
2434
  return error;
2226
2435
  }
2227
2436
 
2228
- int git_repository_foreach_head(git_repository *repo,
2229
- git_repository_foreach_head_cb cb,
2230
- int flags, void *payload)
2437
+ int git_repository_foreach_worktree(git_repository *repo,
2438
+ git_repository_foreach_worktree_cb cb,
2439
+ void *payload)
2231
2440
  {
2232
- git_strarray worktrees = GIT_VECTOR_INIT;
2233
- git_buf path = GIT_BUF_INIT;
2234
- int error = 0;
2441
+ git_strarray worktrees = {0};
2442
+ git_repository *worktree_repo = NULL;
2443
+ git_worktree *worktree = NULL;
2444
+ int error;
2235
2445
  size_t i;
2236
2446
 
2447
+ /* apply operation to repository supplied when commondir is empty, implying there's
2448
+ * no linked worktrees to iterate, which can occur when using custom odb/refdb
2449
+ */
2450
+ if (!repo->commondir)
2451
+ return cb(repo, payload);
2237
2452
 
2238
- if (!(flags & GIT_REPOSITORY_FOREACH_HEAD_SKIP_REPO)) {
2239
- /* Gather HEAD of main repository */
2240
- if ((error = git_buf_joinpath(&path, repo->commondir, GIT_HEAD_FILE)) < 0 ||
2241
- (error = cb(repo, path.ptr, payload) != 0))
2242
- goto out;
2243
- }
2453
+ if ((error = git_repository_open(&worktree_repo, repo->commondir)) < 0 ||
2454
+ (error = cb(worktree_repo, payload) != 0))
2455
+ goto out;
2244
2456
 
2245
- if (!(flags & GIT_REPOSITORY_FOREACH_HEAD_SKIP_WORKTREES)) {
2246
- if ((error = git_worktree_list(&worktrees, repo)) < 0) {
2247
- error = 0;
2248
- goto out;
2249
- }
2457
+ git_repository_free(worktree_repo);
2458
+ worktree_repo = NULL;
2459
+
2460
+ if ((error = git_worktree_list(&worktrees, repo)) < 0)
2461
+ goto out;
2250
2462
 
2251
- /* Gather HEADs of all worktrees */
2252
- for (i = 0; i < worktrees.count; i++) {
2253
- if (get_worktree_file_path(&path, repo, worktrees.strings[i], GIT_HEAD_FILE) < 0)
2254
- continue;
2463
+ for (i = 0; i < worktrees.count; i++) {
2464
+ git_repository_free(worktree_repo);
2465
+ worktree_repo = NULL;
2466
+ git_worktree_free(worktree);
2467
+ worktree = NULL;
2255
2468
 
2256
- if ((error = cb(repo, path.ptr, payload)) != 0)
2469
+ if ((error = git_worktree_lookup(&worktree, repo, worktrees.strings[i]) < 0) ||
2470
+ (error = git_repository_open_from_worktree(&worktree_repo, worktree)) < 0) {
2471
+ if (error != GIT_ENOTFOUND)
2257
2472
  goto out;
2473
+ error = 0;
2474
+ continue;
2258
2475
  }
2476
+
2477
+ if ((error = cb(worktree_repo, payload)) != 0)
2478
+ goto out;
2259
2479
  }
2260
2480
 
2261
2481
  out:
2262
- git_buf_dispose(&path);
2263
- git_strarray_free(&worktrees);
2482
+ git_strarray_dispose(&worktrees);
2483
+ git_repository_free(worktree_repo);
2484
+ git_worktree_free(worktree);
2264
2485
  return error;
2265
2486
  }
2266
2487
 
@@ -2283,43 +2504,79 @@ int git_repository_head_unborn(git_repository *repo)
2283
2504
  return 0;
2284
2505
  }
2285
2506
 
2286
- static int at_least_one_cb(const char *refname, void *payload)
2507
+ static int repo_contains_no_reference(git_repository *repo)
2287
2508
  {
2288
- GIT_UNUSED(refname);
2289
- GIT_UNUSED(payload);
2290
- return GIT_PASSTHROUGH;
2509
+ git_reference_iterator *iter;
2510
+ const char *refname;
2511
+ int error;
2512
+
2513
+ if ((error = git_reference_iterator_new(&iter, repo)) < 0)
2514
+ return error;
2515
+
2516
+ error = git_reference_next_name(&refname, iter);
2517
+ git_reference_iterator_free(iter);
2518
+
2519
+ if (error == GIT_ITEROVER)
2520
+ return 1;
2521
+
2522
+ return error;
2291
2523
  }
2292
2524
 
2293
- static int repo_contains_no_reference(git_repository *repo)
2525
+ int git_repository_initialbranch(git_buf *out, git_repository *repo)
2294
2526
  {
2295
- int error = git_reference_foreach_name(repo, &at_least_one_cb, NULL);
2527
+ git_config *config;
2528
+ git_config_entry *entry = NULL;
2529
+ const char *branch;
2530
+ int valid, error;
2296
2531
 
2297
- if (error == GIT_PASSTHROUGH)
2298
- return 0;
2532
+ if ((error = git_repository_config__weakptr(&config, repo)) < 0)
2533
+ return error;
2299
2534
 
2300
- if (!error)
2301
- return 1;
2535
+ if ((error = git_config_get_entry(&entry, config, "init.defaultbranch")) == 0 &&
2536
+ *entry->value) {
2537
+ branch = entry->value;
2538
+ }
2539
+ else if (!error || error == GIT_ENOTFOUND) {
2540
+ branch = GIT_BRANCH_DEFAULT;
2541
+ }
2542
+ else {
2543
+ goto done;
2544
+ }
2545
+
2546
+ if ((error = git_buf_puts(out, GIT_REFS_HEADS_DIR)) < 0 ||
2547
+ (error = git_buf_puts(out, branch)) < 0 ||
2548
+ (error = git_reference_name_is_valid(&valid, out->ptr)) < 0)
2549
+ goto done;
2302
2550
 
2551
+ if (!valid) {
2552
+ git_error_set(GIT_ERROR_INVALID, "the value of init.defaultBranch is not a valid branch name");
2553
+ error = -1;
2554
+ }
2555
+
2556
+ done:
2557
+ git_config_entry_free(entry);
2303
2558
  return error;
2304
2559
  }
2305
2560
 
2306
2561
  int git_repository_is_empty(git_repository *repo)
2307
2562
  {
2308
2563
  git_reference *head = NULL;
2309
- int is_empty = 0;
2564
+ git_buf initialbranch = GIT_BUF_INIT;
2565
+ int result = 0;
2310
2566
 
2311
- if (git_reference_lookup(&head, repo, GIT_HEAD_FILE) < 0)
2312
- return -1;
2567
+ if ((result = git_reference_lookup(&head, repo, GIT_HEAD_FILE)) < 0 ||
2568
+ (result = git_repository_initialbranch(&initialbranch, repo)) < 0)
2569
+ goto done;
2313
2570
 
2314
- if (git_reference_type(head) == GIT_REFERENCE_SYMBOLIC)
2315
- is_empty =
2316
- (strcmp(git_reference_symbolic_target(head),
2317
- GIT_REFS_HEADS_DIR "master") == 0) &&
2318
- repo_contains_no_reference(repo);
2571
+ result = (git_reference_type(head) == GIT_REFERENCE_SYMBOLIC &&
2572
+ strcmp(git_reference_symbolic_target(head), initialbranch.ptr) == 0 &&
2573
+ repo_contains_no_reference(repo));
2319
2574
 
2575
+ done:
2320
2576
  git_reference_free(head);
2577
+ git_buf_dispose(&initialbranch);
2321
2578
 
2322
- return is_empty;
2579
+ return result;
2323
2580
  }
2324
2581
 
2325
2582
  static const char *resolved_parent_path(const git_repository *repo, git_repository_item_t item, git_repository_item_t fallback)
@@ -2372,13 +2629,13 @@ int git_repository_item_path(git_buf *out, const git_repository *repo, git_repos
2372
2629
 
2373
2630
  const char *git_repository_path(const git_repository *repo)
2374
2631
  {
2375
- assert(repo);
2632
+ GIT_ASSERT_ARG_WITH_RETVAL(repo, NULL);
2376
2633
  return repo->gitdir;
2377
2634
  }
2378
2635
 
2379
2636
  const char *git_repository_workdir(const git_repository *repo)
2380
2637
  {
2381
- assert(repo);
2638
+ GIT_ASSERT_ARG_WITH_RETVAL(repo, NULL);
2382
2639
 
2383
2640
  if (repo->is_bare)
2384
2641
  return NULL;
@@ -2386,9 +2643,25 @@ const char *git_repository_workdir(const git_repository *repo)
2386
2643
  return repo->workdir;
2387
2644
  }
2388
2645
 
2646
+ int git_repository_workdir_path(
2647
+ git_buf *out, git_repository *repo, const char *path)
2648
+ {
2649
+ int error;
2650
+
2651
+ if (!repo->workdir) {
2652
+ git_error_set(GIT_ERROR_REPOSITORY, "repository has no working directory");
2653
+ return GIT_EBAREREPO;
2654
+ }
2655
+
2656
+ if (!(error = git_buf_joinpath(out, repo->workdir, path)))
2657
+ error = git_path_validate_workdir_buf(repo, out);
2658
+
2659
+ return error;
2660
+ }
2661
+
2389
2662
  const char *git_repository_commondir(const git_repository *repo)
2390
2663
  {
2391
- assert(repo);
2664
+ GIT_ASSERT_ARG_WITH_RETVAL(repo, NULL);
2392
2665
  return repo->commondir;
2393
2666
  }
2394
2667
 
@@ -2398,7 +2671,8 @@ int git_repository_set_workdir(
2398
2671
  int error = 0;
2399
2672
  git_buf path = GIT_BUF_INIT;
2400
2673
 
2401
- assert(repo && workdir);
2674
+ GIT_ASSERT_ARG(repo);
2675
+ GIT_ASSERT_ARG(workdir);
2402
2676
 
2403
2677
  if (git_path_prettify_dir(&path, workdir, NULL) < 0)
2404
2678
  return -1;
@@ -2438,13 +2712,13 @@ int git_repository_set_workdir(
2438
2712
 
2439
2713
  int git_repository_is_bare(const git_repository *repo)
2440
2714
  {
2441
- assert(repo);
2715
+ GIT_ASSERT_ARG(repo);
2442
2716
  return repo->is_bare;
2443
2717
  }
2444
2718
 
2445
2719
  int git_repository_is_worktree(const git_repository *repo)
2446
2720
  {
2447
- assert(repo);
2721
+ GIT_ASSERT_ARG(repo);
2448
2722
  return repo->is_worktree;
2449
2723
  }
2450
2724
 
@@ -2453,7 +2727,7 @@ int git_repository_set_bare(git_repository *repo)
2453
2727
  int error;
2454
2728
  git_config *config;
2455
2729
 
2456
- assert(repo);
2730
+ GIT_ASSERT_ARG(repo);
2457
2731
 
2458
2732
  if (repo->is_bare)
2459
2733
  return 0;
@@ -2521,7 +2795,8 @@ int git_repository_message(git_buf *out, git_repository *repo)
2521
2795
  struct stat st;
2522
2796
  int error;
2523
2797
 
2524
- git_buf_sanitize(out);
2798
+ if ((error = git_buf_sanitize(out)) < 0)
2799
+ return error;
2525
2800
 
2526
2801
  if (git_buf_joinpath(&path, repo->gitdir, GIT_MERGE_MSG_FILE) < 0)
2527
2802
  return -1;
@@ -2565,31 +2840,36 @@ int git_repository_hashfile(
2565
2840
  git_file fd = -1;
2566
2841
  uint64_t len;
2567
2842
  git_buf full_path = GIT_BUF_INIT;
2843
+ const char *workdir = git_repository_workdir(repo);
2568
2844
 
2569
- assert(out && path && repo); /* as_path can be NULL */
2570
-
2571
- /* At some point, it would be nice if repo could be NULL to just
2572
- * apply filter rules defined in system and global files, but for
2573
- * now that is not possible because git_filters_load() needs it.
2574
- */
2845
+ /* as_path can be NULL */
2846
+ GIT_ASSERT_ARG(out);
2847
+ GIT_ASSERT_ARG(path);
2848
+ GIT_ASSERT_ARG(repo);
2575
2849
 
2576
- error = git_path_join_unrooted(
2577
- &full_path, path, git_repository_workdir(repo), NULL);
2578
- if (error < 0)
2850
+ if ((error = git_path_join_unrooted(&full_path, path, workdir, NULL)) < 0 ||
2851
+ (error = git_path_validate_workdir_buf(repo, &full_path)) < 0)
2579
2852
  return error;
2580
2853
 
2581
- if (!as_path)
2582
- as_path = path;
2854
+ /*
2855
+ * NULL as_path means that we should derive it from the
2856
+ * given path.
2857
+ */
2858
+ if (!as_path) {
2859
+ if (workdir && !git__prefixcmp(full_path.ptr, workdir))
2860
+ as_path = full_path.ptr + strlen(workdir);
2861
+ else
2862
+ as_path = "";
2863
+ }
2583
2864
 
2584
2865
  /* passing empty string for "as_path" indicated --no-filters */
2585
2866
  if (strlen(as_path) > 0) {
2586
2867
  error = git_filter_list_load(
2587
2868
  &fl, repo, NULL, as_path,
2588
2869
  GIT_FILTER_TO_ODB, GIT_FILTER_DEFAULT);
2870
+
2589
2871
  if (error < 0)
2590
2872
  return error;
2591
- } else {
2592
- error = 0;
2593
2873
  }
2594
2874
 
2595
2875
  /* at this point, error is a count of the number of loaded filters */
@@ -2651,7 +2931,8 @@ static int detach(git_repository *repo, const git_oid *id, const char *new)
2651
2931
  git_object *object = NULL, *peeled = NULL;
2652
2932
  git_reference *new_head = NULL, *current = NULL;
2653
2933
 
2654
- assert(repo && id);
2934
+ GIT_ASSERT_ARG(repo);
2935
+ GIT_ASSERT_ARG(id);
2655
2936
 
2656
2937
  if ((error = git_reference_lookup(&current, repo, GIT_HEAD_FILE)) < 0)
2657
2938
  return error;
@@ -2680,14 +2961,15 @@ cleanup:
2680
2961
  }
2681
2962
 
2682
2963
  int git_repository_set_head(
2683
- git_repository* repo,
2684
- const char* refname)
2964
+ git_repository *repo,
2965
+ const char *refname)
2685
2966
  {
2686
2967
  git_reference *ref = NULL, *current = NULL, *new_head = NULL;
2687
2968
  git_buf log_message = GIT_BUF_INIT;
2688
2969
  int error;
2689
2970
 
2690
- assert(repo && refname);
2971
+ GIT_ASSERT_ARG(repo);
2972
+ GIT_ASSERT_ARG(refname);
2691
2973
 
2692
2974
  if ((error = git_reference_lookup(&current, repo, GIT_HEAD_FILE)) < 0)
2693
2975
  return error;
@@ -2729,8 +3011,8 @@ cleanup:
2729
3011
  }
2730
3012
 
2731
3013
  int git_repository_set_head_detached(
2732
- git_repository* repo,
2733
- const git_oid* commitish)
3014
+ git_repository *repo,
3015
+ const git_oid *commitish)
2734
3016
  {
2735
3017
  return detach(repo, commitish, NULL);
2736
3018
  }
@@ -2739,19 +3021,20 @@ int git_repository_set_head_detached_from_annotated(
2739
3021
  git_repository *repo,
2740
3022
  const git_annotated_commit *commitish)
2741
3023
  {
2742
- assert(repo && commitish);
3024
+ GIT_ASSERT_ARG(repo);
3025
+ GIT_ASSERT_ARG(commitish);
2743
3026
 
2744
3027
  return detach(repo, git_annotated_commit_id(commitish), commitish->description);
2745
3028
  }
2746
3029
 
2747
- int git_repository_detach_head(git_repository* repo)
3030
+ int git_repository_detach_head(git_repository *repo)
2748
3031
  {
2749
3032
  git_reference *old_head = NULL, *new_head = NULL, *current = NULL;
2750
3033
  git_object *object = NULL;
2751
3034
  git_buf log_message = GIT_BUF_INIT;
2752
3035
  int error;
2753
3036
 
2754
- assert(repo);
3037
+ GIT_ASSERT_ARG(repo);
2755
3038
 
2756
3039
  if ((error = git_reference_lookup(&current, repo, GIT_HEAD_FILE)) < 0)
2757
3040
  return error;
@@ -2786,7 +3069,7 @@ int git_repository_state(git_repository *repo)
2786
3069
  git_buf repo_path = GIT_BUF_INIT;
2787
3070
  int state = GIT_REPOSITORY_STATE_NONE;
2788
3071
 
2789
- assert(repo);
3072
+ GIT_ASSERT_ARG(repo);
2790
3073
 
2791
3074
  if (git_buf_puts(&repo_path, repo->gitdir) < 0)
2792
3075
  return -1;
@@ -2863,7 +3146,7 @@ static const char *state_files[] = {
2863
3146
 
2864
3147
  int git_repository_state_cleanup(git_repository *repo)
2865
3148
  {
2866
- assert(repo);
3149
+ GIT_ASSERT_ARG(repo);
2867
3150
 
2868
3151
  return git_repository__cleanup_files(repo, state_files, ARRAY_SIZE(state_files));
2869
3152
  }
@@ -2899,11 +3182,13 @@ int git_repository_init_options_init(
2899
3182
  return 0;
2900
3183
  }
2901
3184
 
3185
+ #ifndef GIT_DEPRECATE_HARD
2902
3186
  int git_repository_init_init_options(
2903
3187
  git_repository_init_options *opts, unsigned int version)
2904
3188
  {
2905
3189
  return git_repository_init_options_init(opts, version);
2906
3190
  }
3191
+ #endif
2907
3192
 
2908
3193
  int git_repository_ident(const char **name, const char **email, const git_repository *repo)
2909
3194
  {
@@ -2927,8 +3212,8 @@ int git_repository_set_ident(git_repository *repo, const char *name, const char
2927
3212
  GIT_ERROR_CHECK_ALLOC(tmp_email);
2928
3213
  }
2929
3214
 
2930
- tmp_name = git__swap(repo->ident_name, tmp_name);
2931
- tmp_email = git__swap(repo->ident_email, tmp_email);
3215
+ tmp_name = git_atomic_swap(repo->ident_name, tmp_name);
3216
+ tmp_email = git_atomic_swap(repo->ident_email, tmp_email);
2932
3217
 
2933
3218
  git__free(tmp_name);
2934
3219
  git__free(tmp_email);
@@ -2938,28 +3223,16 @@ int git_repository_set_ident(git_repository *repo, const char *name, const char
2938
3223
 
2939
3224
  int git_repository_submodule_cache_all(git_repository *repo)
2940
3225
  {
2941
- int error;
2942
-
2943
- assert(repo);
2944
-
2945
- if ((error = git_strmap_new(&repo->submodule_cache)))
2946
- return error;
2947
-
2948
- error = git_submodule__map(repo, repo->submodule_cache);
2949
- return error;
3226
+ GIT_ASSERT_ARG(repo);
3227
+ return git_submodule_cache_init(&repo->submodule_cache, repo);
2950
3228
  }
2951
3229
 
2952
3230
  int git_repository_submodule_cache_clear(git_repository *repo)
2953
3231
  {
2954
- git_submodule *sm;
2955
- assert(repo);
2956
- if (repo->submodule_cache == NULL) {
2957
- return 0;
2958
- }
2959
- git_strmap_foreach_value(repo->submodule_cache, sm, {
2960
- git_submodule_free(sm);
2961
- });
2962
- git_strmap_free(repo->submodule_cache);
2963
- repo->submodule_cache = 0;
2964
- return 0;
3232
+ int error = 0;
3233
+ GIT_ASSERT_ARG(repo);
3234
+
3235
+ error = git_submodule_cache_free(repo->submodule_cache);
3236
+ repo->submodule_cache = NULL;
3237
+ return error;
2965
3238
  }