rugged 1.1.1 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (277) 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_object.c +1 -1
  6. data/ext/rugged/rugged_repo.c +3 -3
  7. data/lib/rugged/repository.rb +2 -2
  8. data/lib/rugged/version.rb +1 -1
  9. data/vendor/libgit2/CMakeLists.txt +11 -6
  10. data/vendor/libgit2/COPYING +109 -1
  11. data/vendor/libgit2/cmake/Findfutimens.cmake +14 -0
  12. data/vendor/libgit2/cmake/SelectHTTPSBackend.cmake +4 -0
  13. data/vendor/libgit2/cmake/SelectHashes.cmake +1 -0
  14. data/vendor/libgit2/deps/chromium-zlib/CMakeLists.txt +101 -0
  15. data/vendor/libgit2/deps/ntlmclient/CMakeLists.txt +17 -5
  16. data/vendor/libgit2/deps/ntlmclient/crypt.h +14 -9
  17. data/vendor/libgit2/deps/ntlmclient/crypt_commoncrypto.c +20 -20
  18. data/vendor/libgit2/deps/ntlmclient/crypt_commoncrypto.h +3 -3
  19. data/vendor/libgit2/deps/ntlmclient/crypt_mbedtls.c +37 -36
  20. data/vendor/libgit2/deps/ntlmclient/crypt_mbedtls.h +4 -3
  21. data/vendor/libgit2/deps/ntlmclient/crypt_openssl.c +178 -51
  22. data/vendor/libgit2/deps/ntlmclient/crypt_openssl.h +74 -5
  23. data/vendor/libgit2/deps/ntlmclient/ntlm.c +150 -118
  24. data/vendor/libgit2/deps/ntlmclient/ntlm.h +13 -9
  25. data/vendor/libgit2/deps/ntlmclient/ntlmclient.h +16 -3
  26. data/vendor/libgit2/deps/ntlmclient/unicode.h +10 -4
  27. data/vendor/libgit2/deps/ntlmclient/unicode_builtin.c +16 -27
  28. data/vendor/libgit2/deps/ntlmclient/unicode_builtin.h +20 -0
  29. data/vendor/libgit2/deps/ntlmclient/unicode_iconv.c +28 -52
  30. data/vendor/libgit2/deps/ntlmclient/unicode_iconv.h +22 -0
  31. data/vendor/libgit2/include/git2/attr.h +89 -0
  32. data/vendor/libgit2/include/git2/blame.h +93 -42
  33. data/vendor/libgit2/include/git2/blob.h +14 -2
  34. data/vendor/libgit2/include/git2/branch.h +25 -0
  35. data/vendor/libgit2/include/git2/cert.h +42 -5
  36. data/vendor/libgit2/include/git2/checkout.h +28 -12
  37. data/vendor/libgit2/include/git2/commit.h +35 -19
  38. data/vendor/libgit2/include/git2/common.h +14 -4
  39. data/vendor/libgit2/include/git2/deprecated.h +206 -6
  40. data/vendor/libgit2/include/git2/diff.h +34 -19
  41. data/vendor/libgit2/include/git2/errors.h +6 -6
  42. data/vendor/libgit2/include/git2/filter.h +57 -17
  43. data/vendor/libgit2/include/git2/graph.h +20 -2
  44. data/vendor/libgit2/include/git2/index.h +2 -2
  45. data/vendor/libgit2/include/git2/odb.h +29 -0
  46. data/vendor/libgit2/include/git2/patch.h +8 -0
  47. data/vendor/libgit2/include/git2/rebase.h +25 -1
  48. data/vendor/libgit2/include/git2/refs.h +6 -2
  49. data/vendor/libgit2/include/git2/remote.h +59 -6
  50. data/vendor/libgit2/include/git2/revparse.h +5 -5
  51. data/vendor/libgit2/include/git2/status.h +115 -59
  52. data/vendor/libgit2/include/git2/submodule.h +9 -0
  53. data/vendor/libgit2/include/git2/sys/commit_graph.h +174 -0
  54. data/vendor/libgit2/include/git2/sys/filter.h +49 -28
  55. data/vendor/libgit2/include/git2/sys/midx.h +74 -0
  56. data/vendor/libgit2/include/git2/sys/odb_backend.h +7 -0
  57. data/vendor/libgit2/include/git2/sys/transport.h +1 -0
  58. data/vendor/libgit2/include/git2/tag.h +12 -0
  59. data/vendor/libgit2/include/git2/tree.h +0 -14
  60. data/vendor/libgit2/include/git2/types.h +9 -0
  61. data/vendor/libgit2/include/git2/version.h +4 -4
  62. data/vendor/libgit2/include/git2/worktree.h +1 -0
  63. data/vendor/libgit2/src/CMakeLists.txt +25 -4
  64. data/vendor/libgit2/src/alloc.c +21 -8
  65. data/vendor/libgit2/src/allocators/failalloc.c +92 -0
  66. data/vendor/libgit2/src/allocators/failalloc.h +23 -0
  67. data/vendor/libgit2/src/allocators/stdalloc.c +41 -10
  68. data/vendor/libgit2/src/allocators/win32_leakcheck.c +118 -0
  69. data/vendor/libgit2/src/allocators/{win32_crtdbg.h → win32_leakcheck.h} +3 -3
  70. data/vendor/libgit2/src/annotated_commit.c +21 -9
  71. data/vendor/libgit2/src/apply.c +16 -7
  72. data/vendor/libgit2/src/array.h +11 -11
  73. data/vendor/libgit2/src/attr.c +181 -74
  74. data/vendor/libgit2/src/attr_file.c +84 -39
  75. data/vendor/libgit2/src/attr_file.h +32 -11
  76. data/vendor/libgit2/src/attrcache.c +42 -37
  77. data/vendor/libgit2/src/attrcache.h +4 -5
  78. data/vendor/libgit2/src/blame.c +11 -5
  79. data/vendor/libgit2/src/blob.c +35 -24
  80. data/vendor/libgit2/src/branch.c +69 -17
  81. data/vendor/libgit2/src/buffer.c +334 -25
  82. data/vendor/libgit2/src/buffer.h +153 -2
  83. data/vendor/libgit2/src/cache.c +2 -2
  84. data/vendor/libgit2/src/cache.h +7 -7
  85. data/vendor/libgit2/src/cc-compat.h +10 -2
  86. data/vendor/libgit2/src/checkout.c +48 -26
  87. data/vendor/libgit2/src/cherrypick.c +6 -2
  88. data/vendor/libgit2/src/clone.c +41 -47
  89. data/vendor/libgit2/src/commit.c +41 -28
  90. data/vendor/libgit2/src/commit_graph.c +1209 -0
  91. data/vendor/libgit2/src/commit_graph.h +162 -0
  92. data/vendor/libgit2/src/commit_list.c +46 -0
  93. data/vendor/libgit2/src/commit_list.h +2 -0
  94. data/vendor/libgit2/src/common.h +25 -2
  95. data/vendor/libgit2/src/config.c +37 -15
  96. data/vendor/libgit2/src/config_cache.c +5 -3
  97. data/vendor/libgit2/src/config_file.c +16 -8
  98. data/vendor/libgit2/src/config_parse.c +4 -6
  99. data/vendor/libgit2/src/crlf.c +16 -6
  100. data/vendor/libgit2/src/date.c +4 -3
  101. data/vendor/libgit2/src/delta.c +1 -1
  102. data/vendor/libgit2/src/describe.c +6 -3
  103. data/vendor/libgit2/src/diff.c +11 -8
  104. data/vendor/libgit2/src/diff_driver.c +21 -17
  105. data/vendor/libgit2/src/diff_file.c +2 -6
  106. data/vendor/libgit2/src/diff_generate.c +46 -17
  107. data/vendor/libgit2/src/diff_print.c +19 -6
  108. data/vendor/libgit2/src/diff_stats.c +7 -5
  109. data/vendor/libgit2/src/diff_tform.c +9 -8
  110. data/vendor/libgit2/src/diff_xdiff.c +4 -2
  111. data/vendor/libgit2/src/diff_xdiff.h +1 -1
  112. data/vendor/libgit2/src/errors.c +24 -19
  113. data/vendor/libgit2/src/features.h.in +5 -1
  114. data/vendor/libgit2/src/fetch.c +5 -2
  115. data/vendor/libgit2/src/fetchhead.c +8 -4
  116. data/vendor/libgit2/src/filebuf.c +9 -7
  117. data/vendor/libgit2/src/filter.c +206 -110
  118. data/vendor/libgit2/src/filter.h +24 -5
  119. data/vendor/libgit2/src/futils.c +5 -5
  120. data/vendor/libgit2/src/futils.h +1 -1
  121. data/vendor/libgit2/src/graph.c +64 -9
  122. data/vendor/libgit2/src/hash/sha1/collisiondetect.c +3 -3
  123. data/vendor/libgit2/src/hash/sha1/common_crypto.c +3 -3
  124. data/vendor/libgit2/src/hash/sha1/generic.h +1 -1
  125. data/vendor/libgit2/src/hash/sha1/mbedtls.c +12 -12
  126. data/vendor/libgit2/src/hash/sha1/openssl.c +3 -3
  127. data/vendor/libgit2/src/hash/sha1/sha1dc/sha1.c +0 -2
  128. data/vendor/libgit2/src/hash/sha1/win32.c +15 -11
  129. data/vendor/libgit2/src/hash.c +16 -13
  130. data/vendor/libgit2/src/hash.h +1 -1
  131. data/vendor/libgit2/src/hashsig.c +23 -10
  132. data/vendor/libgit2/src/ident.c +13 -3
  133. data/vendor/libgit2/src/ignore.c +35 -19
  134. data/vendor/libgit2/src/index.c +106 -70
  135. data/vendor/libgit2/src/index.h +1 -1
  136. data/vendor/libgit2/src/indexer.c +31 -29
  137. data/vendor/libgit2/src/integer.h +64 -2
  138. data/vendor/libgit2/src/iterator.c +36 -24
  139. data/vendor/libgit2/src/iterator.h +1 -1
  140. data/vendor/libgit2/src/khash.h +2 -11
  141. data/vendor/libgit2/src/{settings.c → libgit2.c} +117 -50
  142. data/vendor/libgit2/src/libgit2.h +15 -0
  143. data/vendor/libgit2/src/mailmap.c +23 -10
  144. data/vendor/libgit2/src/map.h +3 -3
  145. data/vendor/libgit2/src/merge.c +70 -30
  146. data/vendor/libgit2/src/merge.h +2 -1
  147. data/vendor/libgit2/src/merge_driver.c +19 -13
  148. data/vendor/libgit2/src/merge_file.c +11 -3
  149. data/vendor/libgit2/src/message.c +3 -1
  150. data/vendor/libgit2/src/midx.c +471 -10
  151. data/vendor/libgit2/src/midx.h +28 -1
  152. data/vendor/libgit2/src/mwindow.c +103 -59
  153. data/vendor/libgit2/src/mwindow.h +3 -3
  154. data/vendor/libgit2/src/net.c +127 -3
  155. data/vendor/libgit2/src/net.h +16 -2
  156. data/vendor/libgit2/src/netops.c +6 -4
  157. data/vendor/libgit2/src/netops.h +2 -2
  158. data/vendor/libgit2/src/notes.c +10 -10
  159. data/vendor/libgit2/src/object.c +22 -14
  160. data/vendor/libgit2/src/odb.c +285 -48
  161. data/vendor/libgit2/src/odb.h +16 -2
  162. data/vendor/libgit2/src/odb_loose.c +28 -18
  163. data/vendor/libgit2/src/odb_mempack.c +1 -1
  164. data/vendor/libgit2/src/odb_pack.c +391 -114
  165. data/vendor/libgit2/src/oid.c +5 -4
  166. data/vendor/libgit2/src/pack-objects.c +54 -48
  167. data/vendor/libgit2/src/pack.c +329 -119
  168. data/vendor/libgit2/src/pack.h +25 -7
  169. data/vendor/libgit2/src/patch.c +14 -7
  170. data/vendor/libgit2/src/patch_generate.c +2 -2
  171. data/vendor/libgit2/src/patch_parse.c +2 -1
  172. data/vendor/libgit2/src/path.c +98 -53
  173. data/vendor/libgit2/src/path.h +79 -6
  174. data/vendor/libgit2/src/pathspec.c +8 -8
  175. data/vendor/libgit2/src/pool.c +13 -7
  176. data/vendor/libgit2/src/posix.c +11 -3
  177. data/vendor/libgit2/src/reader.c +10 -6
  178. data/vendor/libgit2/src/rebase.c +93 -49
  179. data/vendor/libgit2/src/refdb.c +30 -13
  180. data/vendor/libgit2/src/refdb_fs.c +121 -69
  181. data/vendor/libgit2/src/reflog.c +19 -14
  182. data/vendor/libgit2/src/refs.c +76 -41
  183. data/vendor/libgit2/src/refspec.c +32 -12
  184. data/vendor/libgit2/src/remote.c +272 -102
  185. data/vendor/libgit2/src/remote.h +2 -1
  186. data/vendor/libgit2/src/repository.c +176 -103
  187. data/vendor/libgit2/src/repository.h +12 -1
  188. data/vendor/libgit2/src/reset.c +7 -6
  189. data/vendor/libgit2/src/revert.c +6 -2
  190. data/vendor/libgit2/src/revparse.c +14 -9
  191. data/vendor/libgit2/src/revwalk.c +32 -15
  192. data/vendor/libgit2/src/runtime.c +162 -0
  193. data/vendor/libgit2/src/runtime.h +62 -0
  194. data/vendor/libgit2/src/settings.h +11 -0
  195. data/vendor/libgit2/src/signature.c +6 -5
  196. data/vendor/libgit2/src/sortedcache.h +10 -8
  197. data/vendor/libgit2/src/stash.c +3 -1
  198. data/vendor/libgit2/src/status.c +7 -4
  199. data/vendor/libgit2/src/strarray.c +2 -1
  200. data/vendor/libgit2/src/streams/mbedtls.c +14 -17
  201. data/vendor/libgit2/src/streams/mbedtls.h +1 -1
  202. data/vendor/libgit2/src/streams/openssl.c +101 -201
  203. data/vendor/libgit2/src/streams/openssl.h +9 -1
  204. data/vendor/libgit2/src/streams/openssl_dynamic.c +309 -0
  205. data/vendor/libgit2/src/streams/openssl_dynamic.h +348 -0
  206. data/vendor/libgit2/src/streams/openssl_legacy.c +203 -0
  207. data/vendor/libgit2/src/streams/openssl_legacy.h +63 -0
  208. data/vendor/libgit2/src/streams/registry.c +5 -6
  209. data/vendor/libgit2/src/streams/socket.c +6 -2
  210. data/vendor/libgit2/src/streams/stransport.c +6 -3
  211. data/vendor/libgit2/src/streams/tls.c +5 -3
  212. data/vendor/libgit2/src/submodule.c +128 -62
  213. data/vendor/libgit2/src/submodule.h +9 -9
  214. data/vendor/libgit2/src/sysdir.c +4 -6
  215. data/vendor/libgit2/src/tag.c +47 -11
  216. data/vendor/libgit2/src/thread.c +140 -0
  217. data/vendor/libgit2/src/thread.h +479 -0
  218. data/vendor/libgit2/src/threadstate.c +83 -0
  219. data/vendor/libgit2/src/threadstate.h +24 -0
  220. data/vendor/libgit2/src/trace.c +2 -2
  221. data/vendor/libgit2/src/trace.h +17 -13
  222. data/vendor/libgit2/src/transaction.c +19 -8
  223. data/vendor/libgit2/src/transport.c +3 -3
  224. data/vendor/libgit2/src/transports/auth.c +1 -1
  225. data/vendor/libgit2/src/transports/auth_negotiate.c +11 -4
  226. data/vendor/libgit2/src/transports/auth_ntlm.c +10 -6
  227. data/vendor/libgit2/src/transports/credential.c +15 -7
  228. data/vendor/libgit2/src/transports/git.c +1 -3
  229. data/vendor/libgit2/src/transports/http.c +19 -17
  230. data/vendor/libgit2/src/transports/http.h +1 -0
  231. data/vendor/libgit2/src/transports/httpclient.c +53 -26
  232. data/vendor/libgit2/src/transports/httpclient.h +1 -1
  233. data/vendor/libgit2/src/transports/local.c +3 -3
  234. data/vendor/libgit2/src/transports/smart.c +12 -7
  235. data/vendor/libgit2/src/transports/smart.h +1 -1
  236. data/vendor/libgit2/src/transports/smart_protocol.c +11 -5
  237. data/vendor/libgit2/src/transports/ssh.c +51 -17
  238. data/vendor/libgit2/src/transports/winhttp.c +41 -31
  239. data/vendor/libgit2/src/tree.c +100 -77
  240. data/vendor/libgit2/src/tree.h +1 -0
  241. data/vendor/libgit2/src/tsort.c +0 -2
  242. data/vendor/libgit2/src/unix/map.c +3 -1
  243. data/vendor/libgit2/src/unix/pthread.h +2 -1
  244. data/vendor/libgit2/src/utf8.c +150 -0
  245. data/vendor/libgit2/src/utf8.h +52 -0
  246. data/vendor/libgit2/src/util.c +53 -129
  247. data/vendor/libgit2/src/util.h +33 -39
  248. data/vendor/libgit2/src/vector.c +23 -19
  249. data/vendor/libgit2/src/vector.h +4 -2
  250. data/vendor/libgit2/src/win32/findfile.c +4 -2
  251. data/vendor/libgit2/src/win32/map.c +1 -1
  252. data/vendor/libgit2/src/win32/msvc-compat.h +9 -1
  253. data/vendor/libgit2/src/win32/path_w32.c +22 -24
  254. data/vendor/libgit2/src/win32/path_w32.h +0 -1
  255. data/vendor/libgit2/src/win32/posix_w32.c +7 -1
  256. data/vendor/libgit2/src/win32/precompiled.h +0 -1
  257. data/vendor/libgit2/src/win32/reparse.h +4 -4
  258. data/vendor/libgit2/src/win32/thread.c +24 -15
  259. data/vendor/libgit2/src/win32/thread.h +1 -1
  260. data/vendor/libgit2/src/win32/w32_buffer.c +3 -3
  261. data/vendor/libgit2/src/win32/w32_common.h +18 -9
  262. data/vendor/libgit2/src/win32/{w32_crtdbg_stacktrace.c → w32_leakcheck.c} +269 -33
  263. data/vendor/libgit2/src/win32/w32_leakcheck.h +222 -0
  264. data/vendor/libgit2/src/win32/w32_util.h +6 -6
  265. data/vendor/libgit2/src/worktree.c +27 -16
  266. data/vendor/libgit2/src/zstream.c +1 -1
  267. metadata +32 -16
  268. data/vendor/libgit2/src/allocators/win32_crtdbg.c +0 -118
  269. data/vendor/libgit2/src/buf_text.c +0 -316
  270. data/vendor/libgit2/src/buf_text.h +0 -122
  271. data/vendor/libgit2/src/global.c +0 -363
  272. data/vendor/libgit2/src/global.h +0 -41
  273. data/vendor/libgit2/src/thread-utils.c +0 -58
  274. data/vendor/libgit2/src/thread-utils.h +0 -369
  275. data/vendor/libgit2/src/win32/w32_crtdbg_stacktrace.h +0 -127
  276. data/vendor/libgit2/src/win32/w32_stack.c +0 -188
  277. data/vendor/libgit2/src/win32/w32_stack.h +0 -140
@@ -0,0 +1,203 @@
1
+ /*
2
+ * Copyright (C) the libgit2 contributors. All rights reserved.
3
+ *
4
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
5
+ * a Linking Exception. For full terms see the included COPYING file.
6
+ */
7
+
8
+ #include "streams/openssl.h"
9
+ #include "streams/openssl_legacy.h"
10
+
11
+ #include "runtime.h"
12
+ #include "git2/sys/openssl.h"
13
+
14
+ #if defined(GIT_OPENSSL) && !defined(GIT_OPENSSL_DYNAMIC)
15
+ # include <openssl/ssl.h>
16
+ # include <openssl/err.h>
17
+ # include <openssl/x509v3.h>
18
+ # include <openssl/bio.h>
19
+ #endif
20
+
21
+ #if defined(GIT_OPENSSL_LEGACY) || defined(GIT_OPENSSL_DYNAMIC)
22
+
23
+ /*
24
+ * OpenSSL 1.1 made BIO opaque so we have to use functions to interact with it
25
+ * which do not exist in previous versions. We define these inline functions so
26
+ * we can program against the interface instead of littering the implementation
27
+ * with ifdefs. We do the same for OPENSSL_init_ssl.
28
+ */
29
+
30
+ int OPENSSL_init_ssl__legacy(uint64_t opts, const void *settings)
31
+ {
32
+ GIT_UNUSED(opts);
33
+ GIT_UNUSED(settings);
34
+ SSL_load_error_strings();
35
+ SSL_library_init();
36
+ return 0;
37
+ }
38
+
39
+ BIO_METHOD* BIO_meth_new__legacy(int type, const char *name)
40
+ {
41
+ BIO_METHOD *meth = git__calloc(1, sizeof(BIO_METHOD));
42
+ if (!meth) {
43
+ return NULL;
44
+ }
45
+
46
+ meth->type = type;
47
+ meth->name = name;
48
+
49
+ return meth;
50
+ }
51
+
52
+ void BIO_meth_free__legacy(BIO_METHOD *biom)
53
+ {
54
+ git__free(biom);
55
+ }
56
+
57
+ int BIO_meth_set_write__legacy(BIO_METHOD *biom, int (*write) (BIO *, const char *, int))
58
+ {
59
+ biom->bwrite = write;
60
+ return 1;
61
+ }
62
+
63
+ int BIO_meth_set_read__legacy(BIO_METHOD *biom, int (*read) (BIO *, char *, int))
64
+ {
65
+ biom->bread = read;
66
+ return 1;
67
+ }
68
+
69
+ int BIO_meth_set_puts__legacy(BIO_METHOD *biom, int (*puts) (BIO *, const char *))
70
+ {
71
+ biom->bputs = puts;
72
+ return 1;
73
+ }
74
+
75
+ int BIO_meth_set_gets__legacy(BIO_METHOD *biom, int (*gets) (BIO *, char *, int))
76
+
77
+ {
78
+ biom->bgets = gets;
79
+ return 1;
80
+ }
81
+
82
+ int BIO_meth_set_ctrl__legacy(BIO_METHOD *biom, long (*ctrl) (BIO *, int, long, void *))
83
+ {
84
+ biom->ctrl = ctrl;
85
+ return 1;
86
+ }
87
+
88
+ int BIO_meth_set_create__legacy(BIO_METHOD *biom, int (*create) (BIO *))
89
+ {
90
+ biom->create = create;
91
+ return 1;
92
+ }
93
+
94
+ int BIO_meth_set_destroy__legacy(BIO_METHOD *biom, int (*destroy) (BIO *))
95
+ {
96
+ biom->destroy = destroy;
97
+ return 1;
98
+ }
99
+
100
+ int BIO_get_new_index__legacy(void)
101
+ {
102
+ /* This exists as of 1.1 so before we'd just have 0 */
103
+ return 0;
104
+ }
105
+
106
+ void BIO_set_init__legacy(BIO *b, int init)
107
+ {
108
+ b->init = init;
109
+ }
110
+
111
+ void BIO_set_data__legacy(BIO *a, void *ptr)
112
+ {
113
+ a->ptr = ptr;
114
+ }
115
+
116
+ void *BIO_get_data__legacy(BIO *a)
117
+ {
118
+ return a->ptr;
119
+ }
120
+
121
+ const unsigned char *ASN1_STRING_get0_data__legacy(const ASN1_STRING *x)
122
+ {
123
+ return ASN1_STRING_data((ASN1_STRING *)x);
124
+ }
125
+
126
+ long SSL_CTX_set_options__legacy(SSL_CTX *ctx, long op)
127
+ {
128
+ return SSL_CTX_ctrl(ctx, SSL_CTRL_OPTIONS, op, NULL);
129
+ }
130
+
131
+ # if defined(GIT_THREADS)
132
+ static git_mutex *openssl_locks;
133
+
134
+ static void openssl_locking_function(int mode, int n, const char *file, int line)
135
+ {
136
+ int lock;
137
+
138
+ GIT_UNUSED(file);
139
+ GIT_UNUSED(line);
140
+
141
+ lock = mode & CRYPTO_LOCK;
142
+
143
+ if (lock)
144
+ (void)git_mutex_lock(&openssl_locks[n]);
145
+ else
146
+ git_mutex_unlock(&openssl_locks[n]);
147
+ }
148
+
149
+ static void shutdown_ssl_locking(void)
150
+ {
151
+ int num_locks, i;
152
+
153
+ num_locks = CRYPTO_num_locks();
154
+ CRYPTO_set_locking_callback(NULL);
155
+
156
+ for (i = 0; i < num_locks; ++i)
157
+ git_mutex_free(&openssl_locks[i]);
158
+ git__free(openssl_locks);
159
+ }
160
+
161
+ static void threadid_cb(CRYPTO_THREADID *threadid)
162
+ {
163
+ GIT_UNUSED(threadid);
164
+ CRYPTO_THREADID_set_numeric(threadid, git_thread_currentid());
165
+ }
166
+
167
+ int git_openssl_set_locking(void)
168
+ {
169
+ int num_locks, i;
170
+
171
+ #ifndef GIT_THREADS
172
+ git_error_set(GIT_ERROR_THREAD, "libgit2 was not built with threads");
173
+ return -1;
174
+ #endif
175
+
176
+ #ifdef GIT_OPENSSL_DYNAMIC
177
+ /*
178
+ * This function is required on legacy versions of OpenSSL; when building
179
+ * with dynamically-loaded OpenSSL, we detect whether we loaded it or not.
180
+ */
181
+ if (!CRYPTO_set_locking_callback)
182
+ return 0;
183
+ #endif
184
+
185
+ CRYPTO_THREADID_set_callback(threadid_cb);
186
+
187
+ num_locks = CRYPTO_num_locks();
188
+ openssl_locks = git__calloc(num_locks, sizeof(git_mutex));
189
+ GIT_ERROR_CHECK_ALLOC(openssl_locks);
190
+
191
+ for (i = 0; i < num_locks; i++) {
192
+ if (git_mutex_init(&openssl_locks[i]) != 0) {
193
+ git_error_set(GIT_ERROR_SSL, "failed to initialize openssl locks");
194
+ return -1;
195
+ }
196
+ }
197
+
198
+ CRYPTO_set_locking_callback(openssl_locking_function);
199
+ return git_runtime_shutdown_register(shutdown_ssl_locking);
200
+ }
201
+ #endif /* GIT_THREADS */
202
+
203
+ #endif /* GIT_OPENSSL_LEGACY || GIT_OPENSSL_DYNAMIC */
@@ -0,0 +1,63 @@
1
+ /*
2
+ * Copyright (C) the libgit2 contributors. All rights reserved.
3
+ *
4
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
5
+ * a Linking Exception. For full terms see the included COPYING file.
6
+ */
7
+ #ifndef INCLUDE_streams_openssl_legacy_h__
8
+ #define INCLUDE_streams_openssl_legacy_h__
9
+
10
+ #include "streams/openssl_dynamic.h"
11
+
12
+ #if defined(GIT_OPENSSL) && !defined(GIT_OPENSSL_DYNAMIC)
13
+ # include <openssl/ssl.h>
14
+ # include <openssl/err.h>
15
+ # include <openssl/x509v3.h>
16
+ # include <openssl/bio.h>
17
+
18
+ # if (defined(OPENSSL_VERSION_NUMBER) && OPENSSL_VERSION_NUMBER < 0x10100000L) || \
19
+ (defined(LIBRESSL_VERSION_NUMBER) && LIBRESSL_VERSION_NUMBER < 0x20700000L)
20
+ # define GIT_OPENSSL_LEGACY
21
+ # endif
22
+ #endif
23
+
24
+ #if defined(GIT_OPENSSL_LEGACY) && !defined(GIT_OPENSSL_DYNAMIC)
25
+ # define OPENSSL_init_ssl OPENSSL_init_ssl__legacy
26
+ # define BIO_meth_new BIO_meth_new__legacy
27
+ # define BIO_meth_free BIO_meth_free__legacy
28
+ # define BIO_meth_set_write BIO_meth_set_write__legacy
29
+ # define BIO_meth_set_read BIO_meth_set_read__legacy
30
+ # define BIO_meth_set_puts BIO_meth_set_puts__legacy
31
+ # define BIO_meth_set_gets BIO_meth_set_gets__legacy
32
+ # define BIO_meth_set_ctrl BIO_meth_set_ctrl__legacy
33
+ # define BIO_meth_set_create BIO_meth_set_create__legacy
34
+ # define BIO_meth_set_destroy BIO_meth_set_destroy__legacy
35
+ # define BIO_get_new_index BIO_get_new_index__legacy
36
+ # define BIO_set_data BIO_set_data__legacy
37
+ # define BIO_set_init BIO_set_init__legacy
38
+ # define BIO_get_data BIO_get_data__legacy
39
+ # define ASN1_STRING_get0_data ASN1_STRING_get0_data__legacy
40
+ #endif
41
+
42
+ #if defined(GIT_OPENSSL_LEGACY) || defined(GIT_OPENSSL_DYNAMIC)
43
+
44
+ extern int OPENSSL_init_ssl__legacy(uint64_t opts, const void *settings);
45
+ extern BIO_METHOD* BIO_meth_new__legacy(int type, const char *name);
46
+ extern void BIO_meth_free__legacy(BIO_METHOD *biom);
47
+ extern int BIO_meth_set_write__legacy(BIO_METHOD *biom, int (*write) (BIO *, const char *, int));
48
+ extern int BIO_meth_set_read__legacy(BIO_METHOD *biom, int (*read) (BIO *, char *, int));
49
+ extern int BIO_meth_set_puts__legacy(BIO_METHOD *biom, int (*puts) (BIO *, const char *));
50
+ extern int BIO_meth_set_gets__legacy(BIO_METHOD *biom, int (*gets) (BIO *, char *, int));
51
+ extern int BIO_meth_set_ctrl__legacy(BIO_METHOD *biom, long (*ctrl) (BIO *, int, long, void *));
52
+ extern int BIO_meth_set_create__legacy(BIO_METHOD *biom, int (*create) (BIO *));
53
+ extern int BIO_meth_set_destroy__legacy(BIO_METHOD *biom, int (*destroy) (BIO *));
54
+ extern int BIO_get_new_index__legacy(void);
55
+ extern void BIO_set_data__legacy(BIO *a, void *ptr);
56
+ extern void BIO_set_init__legacy(BIO *b, int init);
57
+ extern void *BIO_get_data__legacy(BIO *a);
58
+ extern const unsigned char *ASN1_STRING_get0_data__legacy(const ASN1_STRING *x);
59
+ extern long SSL_CTX_set_options__legacy(SSL_CTX *ctx, long op);
60
+
61
+ #endif
62
+
63
+ #endif
@@ -9,7 +9,7 @@
9
9
 
10
10
  #include "streams/registry.h"
11
11
 
12
- #include "global.h"
12
+ #include "runtime.h"
13
13
  #include "streams/tls.h"
14
14
  #include "streams/mbedtls.h"
15
15
  #include "streams/openssl.h"
@@ -33,8 +33,7 @@ int git_stream_registry_global_init(void)
33
33
  if (git_rwlock_init(&stream_registry.lock) < 0)
34
34
  return -1;
35
35
 
36
- git__on_shutdown(shutdown_stream_registry);
37
- return 0;
36
+ return git_runtime_shutdown_register(shutdown_stream_registry);
38
37
  }
39
38
 
40
39
  GIT_INLINE(void) stream_registration_cpy(
@@ -52,7 +51,7 @@ int git_stream_registry_lookup(git_stream_registration *out, git_stream_t type)
52
51
  git_stream_registration *target;
53
52
  int error = GIT_ENOTFOUND;
54
53
 
55
- assert(out);
54
+ GIT_ASSERT_ARG(out);
56
55
 
57
56
  switch(type) {
58
57
  case GIT_STREAM_STANDARD:
@@ -62,7 +61,7 @@ int git_stream_registry_lookup(git_stream_registration *out, git_stream_t type)
62
61
  target = &stream_registry.tls_callbacks;
63
62
  break;
64
63
  default:
65
- assert(0);
64
+ git_error_set(GIT_ERROR_INVALID, "invalid stream type");
66
65
  return -1;
67
66
  }
68
67
 
@@ -82,7 +81,7 @@ int git_stream_registry_lookup(git_stream_registration *out, git_stream_t type)
82
81
 
83
82
  int git_stream_register(git_stream_t type, git_stream_registration *registration)
84
83
  {
85
- assert(!registration || registration->init);
84
+ GIT_ASSERT(!registration || registration->init);
86
85
 
87
86
  GIT_ERROR_CHECK_VERSION(registration, GIT_STREAM_VERSION, "stream_registration");
88
87
 
@@ -183,7 +183,9 @@ static int default_socket_stream_new(
183
183
  {
184
184
  git_socket_stream *st;
185
185
 
186
- assert(out && host && port);
186
+ GIT_ASSERT_ARG(out);
187
+ GIT_ASSERT_ARG(host);
188
+ GIT_ASSERT_ARG(port);
187
189
 
188
190
  st = git__calloc(1, sizeof(git_socket_stream));
189
191
  GIT_ERROR_CHECK_ALLOC(st);
@@ -217,7 +219,9 @@ int git_socket_stream_new(
217
219
  git_stream_registration custom = {0};
218
220
  int error;
219
221
 
220
- assert(out && host && port);
222
+ GIT_ASSERT_ARG(out);
223
+ GIT_ASSERT_ARG(host);
224
+ GIT_ASSERT_ARG(port);
221
225
 
222
226
  if ((error = git_stream_registry_lookup(&custom, GIT_STREAM_STANDARD)) == 0)
223
227
  init = custom.init;
@@ -167,7 +167,7 @@ static ssize_t stransport_write(git_stream *stream, const char *data, size_t len
167
167
  if ((ret = SSLWrite(st->ctx, data, data_len, &processed)) != noErr)
168
168
  return stransport_error(ret);
169
169
 
170
- assert(processed < SSIZE_MAX);
170
+ GIT_ASSERT(processed < SSIZE_MAX);
171
171
  return (ssize_t)processed;
172
172
  }
173
173
 
@@ -251,7 +251,9 @@ static int stransport_wrap(
251
251
  stransport_stream *st;
252
252
  OSStatus ret;
253
253
 
254
- assert(out && in && host);
254
+ GIT_ASSERT_ARG(out);
255
+ GIT_ASSERT_ARG(in);
256
+ GIT_ASSERT_ARG(host);
255
257
 
256
258
  st = git__calloc(1, sizeof(stransport_stream));
257
259
  GIT_ERROR_CHECK_ALLOC(st);
@@ -305,7 +307,8 @@ int git_stransport_stream_new(git_stream **out, const char *host, const char *po
305
307
  git_stream *stream = NULL;
306
308
  int error;
307
309
 
308
- assert(out && host);
310
+ GIT_ASSERT_ARG(out);
311
+ GIT_ASSERT_ARG(host);
309
312
 
310
313
  error = git_socket_stream_new(&stream, host, port);
311
314
 
@@ -8,7 +8,6 @@
8
8
  #include "git2/errors.h"
9
9
 
10
10
  #include "common.h"
11
- #include "global.h"
12
11
  #include "streams/registry.h"
13
12
  #include "streams/tls.h"
14
13
  #include "streams/mbedtls.h"
@@ -21,7 +20,9 @@ int git_tls_stream_new(git_stream **out, const char *host, const char *port)
21
20
  git_stream_registration custom = {0};
22
21
  int error;
23
22
 
24
- assert(out && host && port);
23
+ GIT_ASSERT_ARG(out);
24
+ GIT_ASSERT_ARG(host);
25
+ GIT_ASSERT_ARG(port);
25
26
 
26
27
  if ((error = git_stream_registry_lookup(&custom, GIT_STREAM_TLS)) == 0) {
27
28
  init = custom.init;
@@ -50,7 +51,8 @@ int git_tls_stream_wrap(git_stream **out, git_stream *in, const char *host)
50
51
  int (*wrap)(git_stream **, git_stream *, const char *) = NULL;
51
52
  git_stream_registration custom = {0};
52
53
 
53
- assert(out && in);
54
+ GIT_ASSERT_ARG(out);
55
+ GIT_ASSERT_ARG(in);
54
56
 
55
57
  if (git_stream_registry_lookup(&custom, GIT_STREAM_TLS) == 0) {
56
58
  wrap = custom.wrap;
@@ -12,7 +12,6 @@
12
12
  #include "git2/types.h"
13
13
  #include "git2/index.h"
14
14
  #include "buffer.h"
15
- #include "buf_text.h"
16
15
  #include "vector.h"
17
16
  #include "posix.h"
18
17
  #include "config_backend.h"
@@ -249,24 +248,62 @@ out:
249
248
  return error;
250
249
  }
251
250
 
251
+ int git_submodule_cache_init(git_strmap **out, git_repository *repo)
252
+ {
253
+ int error = 0;
254
+ git_strmap *cache = NULL;
255
+ GIT_ASSERT_ARG(out);
256
+ GIT_ASSERT_ARG(repo);
257
+ if ((error = git_strmap_new(&cache)) < 0)
258
+ return error;
259
+ if ((error = git_submodule__map(repo, cache)) < 0) {
260
+ git_submodule_cache_free(cache);
261
+ return error;
262
+ }
263
+ *out = cache;
264
+ return error;
265
+ }
266
+
267
+ int git_submodule_cache_free(git_strmap *cache)
268
+ {
269
+ git_submodule *sm = NULL;
270
+ if (cache == NULL)
271
+ return 0;
272
+ git_strmap_foreach_value(cache, sm, {
273
+ git_submodule_free(sm);
274
+ });
275
+ git_strmap_free(cache);
276
+ return 0;
277
+ }
278
+
252
279
  int git_submodule_lookup(
253
280
  git_submodule **out, /* NULL if user only wants to test existence */
254
281
  git_repository *repo,
255
282
  const char *name) /* trailing slash is allowed */
283
+ {
284
+ return git_submodule__lookup_with_cache(out, repo, name, repo->submodule_cache);
285
+ }
286
+
287
+ int git_submodule__lookup_with_cache(
288
+ git_submodule **out, /* NULL if user only wants to test existence */
289
+ git_repository *repo,
290
+ const char *name, /* trailing slash is allowed */
291
+ git_strmap *cache)
256
292
  {
257
293
  int error;
258
294
  unsigned int location;
259
295
  git_submodule *sm;
260
296
 
261
- assert(repo && name);
297
+ GIT_ASSERT_ARG(repo);
298
+ GIT_ASSERT_ARG(name);
262
299
 
263
300
  if (repo->is_bare) {
264
301
  git_error_set(GIT_ERROR_SUBMODULE, "cannot get submodules without a working tree");
265
302
  return -1;
266
303
  }
267
304
 
268
- if (repo->submodule_cache != NULL) {
269
- if ((sm = git_strmap_get(repo->submodule_cache, name)) != NULL) {
305
+ if (cache != NULL) {
306
+ if ((sm = git_strmap_get(cache, name)) != NULL) {
270
307
  if (out) {
271
308
  *out = sm;
272
309
  GIT_REFCOUNT_INC(*out);
@@ -342,8 +379,10 @@ int git_submodule_lookup(
342
379
  /* If it's not configured, we still check if there's a repo at the path */
343
380
  if (git_repository_workdir(repo)) {
344
381
  git_buf path = GIT_BUF_INIT;
345
- if (git_buf_join3(&path,
346
- '/', git_repository_workdir(repo), name, DOT_GIT) < 0)
382
+ if (git_buf_join3(&path, '/',
383
+ git_repository_workdir(repo),
384
+ name, DOT_GIT) < 0 ||
385
+ git_path_validate_workdir_buf(NULL, &path) < 0)
347
386
  return -1;
348
387
 
349
388
  if (git_path_exists(path.ptr))
@@ -380,7 +419,7 @@ int git_submodule_name_is_valid(git_repository *repo, const char *name, int flag
380
419
  git_buf_attach_notowned(&buf, name, strlen(name));
381
420
  }
382
421
 
383
- isvalid = git_path_isvalid(repo, buf.ptr, 0, flags);
422
+ isvalid = git_path_validate(repo, buf.ptr, 0, flags);
384
423
  git_buf_dispose(&buf);
385
424
 
386
425
  return isvalid;
@@ -515,12 +554,13 @@ int git_submodule__map(git_repository *repo, git_strmap *map)
515
554
  int error = 0;
516
555
  git_index *idx = NULL;
517
556
  git_tree *head = NULL;
518
- const char *wd = NULL;
519
557
  git_buf path = GIT_BUF_INIT;
520
558
  git_submodule *sm;
521
559
  git_config *mods = NULL;
560
+ bool has_workdir;
522
561
 
523
- assert(repo && map);
562
+ GIT_ASSERT_ARG(repo);
563
+ GIT_ASSERT_ARG(map);
524
564
 
525
565
  /* get sources that we will need to check */
526
566
  if (git_repository_index(&idx, repo) < 0)
@@ -528,12 +568,14 @@ int git_submodule__map(git_repository *repo, git_strmap *map)
528
568
  if (git_repository_head_tree(&head, repo) < 0)
529
569
  git_error_clear();
530
570
 
531
- wd = git_repository_workdir(repo);
532
- if (wd && (error = git_buf_joinpath(&path, wd, GIT_MODULES_FILE)) < 0)
571
+ has_workdir = git_repository_workdir(repo) != NULL;
572
+
573
+ if (has_workdir &&
574
+ (error = git_repository_workdir_path(&path, repo, GIT_MODULES_FILE)) < 0)
533
575
  goto cleanup;
534
576
 
535
577
  /* add submodule information from .gitmodules */
536
- if (wd) {
578
+ if (has_workdir) {
537
579
  lfc_data data = { 0 };
538
580
  data.map = map;
539
581
  data.repo = repo;
@@ -560,7 +602,7 @@ int git_submodule__map(git_repository *repo, git_strmap *map)
560
602
  goto cleanup;
561
603
  }
562
604
  /* shallow scan submodules in work tree as needed */
563
- if (wd) {
605
+ if (has_workdir) {
564
606
  git_strmap_foreach_value(map, sm, {
565
607
  submodule_load_from_wd_lite(sm);
566
608
  });
@@ -644,7 +686,7 @@ static int submodule_repo_init(
644
686
  git_repository_init_options initopt = GIT_REPOSITORY_INIT_OPTIONS_INIT;
645
687
  git_repository *subrepo = NULL;
646
688
 
647
- error = git_buf_joinpath(&workdir, git_repository_workdir(parent_repo), path);
689
+ error = git_repository_workdir_path(&workdir, parent_repo, path);
648
690
  if (error < 0)
649
691
  goto cleanup;
650
692
 
@@ -698,7 +740,9 @@ int git_submodule_add_setup(
698
740
  git_repository *subrepo = NULL;
699
741
  bool path_occupied;
700
742
 
701
- assert(repo && url && path);
743
+ GIT_ASSERT_ARG(repo);
744
+ GIT_ASSERT_ARG(url);
745
+ GIT_ASSERT_ARG(path);
702
746
 
703
747
  /* see if there is already an entry for this submodule */
704
748
 
@@ -749,7 +793,7 @@ int git_submodule_add_setup(
749
793
 
750
794
  /* init submodule repository and add origin remote as needed */
751
795
 
752
- error = git_buf_joinpath(&name, git_repository_workdir(repo), path);
796
+ error = git_repository_workdir_path(&name, repo, path);
753
797
  if (error < 0)
754
798
  goto cleanup;
755
799
 
@@ -799,7 +843,8 @@ int git_submodule_repo_init(
799
843
  git_config *cfg = NULL;
800
844
  git_buf buf = GIT_BUF_INIT;
801
845
 
802
- assert(out && sm);
846
+ GIT_ASSERT_ARG(out);
847
+ GIT_ASSERT_ARG(sm);
803
848
 
804
849
  /* get the configured remote url of the submodule */
805
850
  if ((error = git_buf_printf(&buf, "submodule.%s.url", sm->name)) < 0 ||
@@ -840,7 +885,7 @@ int git_submodule_clone(git_repository **out, git_submodule *submodule, const gi
840
885
  git_submodule_update_options sub_opts = GIT_SUBMODULE_UPDATE_OPTIONS_INIT;
841
886
  git_clone_options opts = GIT_CLONE_OPTIONS_INIT;
842
887
 
843
- assert(submodule);
888
+ GIT_ASSERT_ARG(submodule);
844
889
 
845
890
  if (given_opts)
846
891
  memcpy(&sub_opts, given_opts, sizeof(sub_opts));
@@ -854,10 +899,9 @@ int git_submodule_clone(git_repository **out, git_submodule *submodule, const gi
854
899
  opts.remote_cb = clone_return_origin;
855
900
  opts.remote_cb_payload = submodule;
856
901
 
857
- git_buf_puts(&rel_path, git_repository_workdir(git_submodule_owner(submodule)));
858
- git_buf_joinpath(&rel_path, git_buf_cstr(&rel_path), git_submodule_path(submodule));
859
-
860
- GIT_ERROR_CHECK_ALLOC_BUF(&rel_path);
902
+ error = git_repository_workdir_path(&rel_path, git_submodule_owner(submodule), git_submodule_path(submodule));
903
+ if (error < 0)
904
+ goto cleanup;
861
905
 
862
906
  error = git_clone__submodule(&clone, git_submodule_url(submodule), git_buf_cstr(&rel_path), &opts);
863
907
  if (error < 0)
@@ -879,7 +923,7 @@ int git_submodule_add_finalize(git_submodule *sm)
879
923
  int error;
880
924
  git_index *index;
881
925
 
882
- assert(sm);
926
+ GIT_ASSERT_ARG(sm);
883
927
 
884
928
  if ((error = git_repository_index__weakptr(&index, sm->repo)) < 0 ||
885
929
  (error = git_index_add_bypath(index, GIT_MODULES_FILE)) < 0)
@@ -898,15 +942,14 @@ int git_submodule_add_to_index(git_submodule *sm, int write_index)
898
942
  git_index_entry entry;
899
943
  struct stat st;
900
944
 
901
- assert(sm);
945
+ GIT_ASSERT_ARG(sm);
902
946
 
903
947
  /* force reload of wd OID by git_submodule_open */
904
948
  sm->flags = sm->flags & ~GIT_SUBMODULE_STATUS__WD_OID_VALID;
905
949
 
906
950
  if ((error = git_repository_index__weakptr(&index, sm->repo)) < 0 ||
907
- (error = git_buf_joinpath(
908
- &path, git_repository_workdir(sm->repo), sm->path)) < 0 ||
909
- (error = git_submodule_open(&sm_repo, sm)) < 0)
951
+ (error = git_repository_workdir_path(&path, sm->repo, sm->path)) < 0 ||
952
+ (error = git_submodule_open(&sm_repo, sm)) < 0)
910
953
  goto cleanup;
911
954
 
912
955
  /* read stat information for submodule working directory */
@@ -969,25 +1012,25 @@ static const char *submodule_update_to_str(git_submodule_update_t update)
969
1012
 
970
1013
  git_repository *git_submodule_owner(git_submodule *submodule)
971
1014
  {
972
- assert(submodule);
1015
+ GIT_ASSERT_ARG_WITH_RETVAL(submodule, NULL);
973
1016
  return submodule->repo;
974
1017
  }
975
1018
 
976
1019
  const char *git_submodule_name(git_submodule *submodule)
977
1020
  {
978
- assert(submodule);
1021
+ GIT_ASSERT_ARG_WITH_RETVAL(submodule, NULL);
979
1022
  return submodule->name;
980
1023
  }
981
1024
 
982
1025
  const char *git_submodule_path(git_submodule *submodule)
983
1026
  {
984
- assert(submodule);
1027
+ GIT_ASSERT_ARG_WITH_RETVAL(submodule, NULL);
985
1028
  return submodule->path;
986
1029
  }
987
1030
 
988
1031
  const char *git_submodule_url(git_submodule *submodule)
989
1032
  {
990
- assert(submodule);
1033
+ GIT_ASSERT_ARG_WITH_RETVAL(submodule, NULL);
991
1034
  return submodule->url;
992
1035
  }
993
1036
 
@@ -996,9 +1039,12 @@ int git_submodule_resolve_url(git_buf *out, git_repository *repo, const char *ur
996
1039
  int error = 0;
997
1040
  git_buf normalized = GIT_BUF_INIT;
998
1041
 
999
- assert(out && repo && url);
1042
+ GIT_ASSERT_ARG(out);
1043
+ GIT_ASSERT_ARG(repo);
1044
+ GIT_ASSERT_ARG(url);
1000
1045
 
1001
- git_buf_sanitize(out);
1046
+ if ((error = git_buf_sanitize(out)) < 0)
1047
+ return error;
1002
1048
 
1003
1049
  /* We do this in all platforms in case someone on Windows created the .gitmodules */
1004
1050
  if (strchr(url, '\\')) {
@@ -1066,28 +1112,30 @@ static int write_mapped_var(git_repository *repo, const char *name, git_configma
1066
1112
 
1067
1113
  const char *git_submodule_branch(git_submodule *submodule)
1068
1114
  {
1069
- assert(submodule);
1115
+ GIT_ASSERT_ARG_WITH_RETVAL(submodule, NULL);
1070
1116
  return submodule->branch;
1071
1117
  }
1072
1118
 
1073
1119
  int git_submodule_set_branch(git_repository *repo, const char *name, const char *branch)
1074
1120
  {
1075
-
1076
- assert(repo && name);
1121
+ GIT_ASSERT_ARG(repo);
1122
+ GIT_ASSERT_ARG(name);
1077
1123
 
1078
1124
  return write_var(repo, name, "branch", branch);
1079
1125
  }
1080
1126
 
1081
1127
  int git_submodule_set_url(git_repository *repo, const char *name, const char *url)
1082
1128
  {
1083
- assert(repo && name && url);
1129
+ GIT_ASSERT_ARG(repo);
1130
+ GIT_ASSERT_ARG(name);
1131
+ GIT_ASSERT_ARG(url);
1084
1132
 
1085
1133
  return write_var(repo, name, "url", url);
1086
1134
  }
1087
1135
 
1088
1136
  const git_oid *git_submodule_index_id(git_submodule *submodule)
1089
1137
  {
1090
- assert(submodule);
1138
+ GIT_ASSERT_ARG_WITH_RETVAL(submodule, NULL);
1091
1139
 
1092
1140
  if (submodule->flags & GIT_SUBMODULE_STATUS__INDEX_OID_VALID)
1093
1141
  return &submodule->index_oid;
@@ -1097,7 +1145,7 @@ const git_oid *git_submodule_index_id(git_submodule *submodule)
1097
1145
 
1098
1146
  const git_oid *git_submodule_head_id(git_submodule *submodule)
1099
1147
  {
1100
- assert(submodule);
1148
+ GIT_ASSERT_ARG_WITH_RETVAL(submodule, NULL);
1101
1149
 
1102
1150
  if (submodule->flags & GIT_SUBMODULE_STATUS__HEAD_OID_VALID)
1103
1151
  return &submodule->head_oid;
@@ -1107,7 +1155,7 @@ const git_oid *git_submodule_head_id(git_submodule *submodule)
1107
1155
 
1108
1156
  const git_oid *git_submodule_wd_id(git_submodule *submodule)
1109
1157
  {
1110
- assert(submodule);
1158
+ GIT_ASSERT_ARG_WITH_RETVAL(submodule, NULL);
1111
1159
 
1112
1160
  /* load unless we think we have a valid oid */
1113
1161
  if (!(submodule->flags & GIT_SUBMODULE_STATUS__WD_OID_VALID)) {
@@ -1128,28 +1176,32 @@ const git_oid *git_submodule_wd_id(git_submodule *submodule)
1128
1176
 
1129
1177
  git_submodule_ignore_t git_submodule_ignore(git_submodule *submodule)
1130
1178
  {
1131
- assert(submodule);
1179
+ GIT_ASSERT_ARG_WITH_RETVAL(submodule, GIT_SUBMODULE_IGNORE_UNSPECIFIED);
1180
+
1132
1181
  return (submodule->ignore < GIT_SUBMODULE_IGNORE_NONE) ?
1133
1182
  GIT_SUBMODULE_IGNORE_NONE : submodule->ignore;
1134
1183
  }
1135
1184
 
1136
1185
  int git_submodule_set_ignore(git_repository *repo, const char *name, git_submodule_ignore_t ignore)
1137
1186
  {
1138
- assert(repo && name);
1187
+ GIT_ASSERT_ARG(repo);
1188
+ GIT_ASSERT_ARG(name);
1139
1189
 
1140
1190
  return write_mapped_var(repo, name, _sm_ignore_map, ARRAY_SIZE(_sm_ignore_map), "ignore", ignore);
1141
1191
  }
1142
1192
 
1143
1193
  git_submodule_update_t git_submodule_update_strategy(git_submodule *submodule)
1144
1194
  {
1145
- assert(submodule);
1195
+ GIT_ASSERT_ARG_WITH_RETVAL(submodule, GIT_SUBMODULE_UPDATE_NONE);
1196
+
1146
1197
  return (submodule->update < GIT_SUBMODULE_UPDATE_CHECKOUT) ?
1147
1198
  GIT_SUBMODULE_UPDATE_CHECKOUT : submodule->update;
1148
1199
  }
1149
1200
 
1150
1201
  int git_submodule_set_update(git_repository *repo, const char *name, git_submodule_update_t update)
1151
1202
  {
1152
- assert(repo && name);
1203
+ GIT_ASSERT_ARG(repo);
1204
+ GIT_ASSERT_ARG(name);
1153
1205
 
1154
1206
  return write_mapped_var(repo, name, _sm_update_map, ARRAY_SIZE(_sm_update_map), "update", update);
1155
1207
  }
@@ -1157,13 +1209,14 @@ int git_submodule_set_update(git_repository *repo, const char *name, git_submodu
1157
1209
  git_submodule_recurse_t git_submodule_fetch_recurse_submodules(
1158
1210
  git_submodule *submodule)
1159
1211
  {
1160
- assert(submodule);
1212
+ GIT_ASSERT_ARG_WITH_RETVAL(submodule, GIT_SUBMODULE_RECURSE_NO);
1161
1213
  return submodule->fetch_recurse;
1162
1214
  }
1163
1215
 
1164
1216
  int git_submodule_set_fetch_recurse_submodules(git_repository *repo, const char *name, git_submodule_recurse_t recurse)
1165
1217
  {
1166
- assert(repo && name);
1218
+ GIT_ASSERT_ARG(repo);
1219
+ GIT_ASSERT_ARG(name);
1167
1220
 
1168
1221
  return write_mapped_var(repo, name, _sm_recurse_map, ARRAY_SIZE(_sm_recurse_map), "fetchRecurseSubmodules", recurse);
1169
1222
  }
@@ -1185,7 +1238,7 @@ static int submodule_repo_create(
1185
1238
  GIT_REPOSITORY_INIT_RELATIVE_GITLINK;
1186
1239
 
1187
1240
  /* Workdir: path to sub-repo working directory */
1188
- error = git_buf_joinpath(&workdir, git_repository_workdir(parent_repo), path);
1241
+ error = git_repository_workdir_path(&workdir, parent_repo, path);
1189
1242
  if (error < 0)
1190
1243
  goto cleanup;
1191
1244
 
@@ -1260,7 +1313,7 @@ int git_submodule_update(git_submodule *sm, int init, git_submodule_update_optio
1260
1313
  git_submodule_update_options update_options = GIT_SUBMODULE_UPDATE_OPTIONS_INIT;
1261
1314
  git_clone_options clone_options = GIT_CLONE_OPTIONS_INIT;
1262
1315
 
1263
- assert(sm);
1316
+ GIT_ASSERT_ARG(sm);
1264
1317
 
1265
1318
  if (_update_options)
1266
1319
  memcpy(&update_options, _update_options, sizeof(git_submodule_update_options));
@@ -1473,7 +1526,8 @@ static int git_submodule__open(
1473
1526
  unsigned int flags = GIT_REPOSITORY_OPEN_NO_SEARCH;
1474
1527
  const char *wd;
1475
1528
 
1476
- assert(sm && subrepo);
1529
+ GIT_ASSERT_ARG(sm);
1530
+ GIT_ASSERT_ARG(subrepo);
1477
1531
 
1478
1532
  if (git_repository__ensure_not_bare(
1479
1533
  sm->repo, "open submodule repository") < 0)
@@ -1481,8 +1535,7 @@ static int git_submodule__open(
1481
1535
 
1482
1536
  wd = git_repository_workdir(sm->repo);
1483
1537
 
1484
- if (git_buf_joinpath(&path, wd, sm->path) < 0 ||
1485
- git_buf_joinpath(&path, path.ptr, DOT_GIT) < 0)
1538
+ if (git_buf_join3(&path, '/', wd, sm->path, DOT_GIT) < 0)
1486
1539
  return -1;
1487
1540
 
1488
1541
  sm->flags = sm->flags &
@@ -1609,7 +1662,7 @@ int git_submodule_reload(git_submodule *sm, int force)
1609
1662
 
1610
1663
  GIT_UNUSED(force);
1611
1664
 
1612
- assert(sm);
1665
+ GIT_ASSERT_ARG(sm);
1613
1666
 
1614
1667
  if ((error = git_submodule_name_is_valid(sm->repo, sm->name, 0)) <= 0)
1615
1668
  /* This should come with a warning, but we've no API for that */
@@ -1726,7 +1779,9 @@ int git_submodule_status(unsigned int *status, git_repository *repo, const char
1726
1779
  git_submodule *sm;
1727
1780
  int error;
1728
1781
 
1729
- assert(status && repo && name);
1782
+ GIT_ASSERT_ARG(status);
1783
+ GIT_ASSERT_ARG(repo);
1784
+ GIT_ASSERT_ARG(name);
1730
1785
 
1731
1786
  if ((error = git_submodule_lookup(&sm, repo, name)) < 0)
1732
1787
  return error;
@@ -1739,7 +1794,8 @@ int git_submodule_status(unsigned int *status, git_repository *repo, const char
1739
1794
 
1740
1795
  int git_submodule_location(unsigned int *location, git_submodule *sm)
1741
1796
  {
1742
- assert(location && sm);
1797
+ GIT_ASSERT_ARG(location);
1798
+ GIT_ASSERT_ARG(sm);
1743
1799
 
1744
1800
  return git_submodule__status(
1745
1801
  location, NULL, NULL, NULL, sm, GIT_SUBMODULE_IGNORE_ALL);
@@ -1798,6 +1854,17 @@ static void submodule_release(git_submodule *sm)
1798
1854
  git__free(sm);
1799
1855
  }
1800
1856
 
1857
+ int git_submodule_dup(git_submodule **out, git_submodule *source)
1858
+ {
1859
+ GIT_ASSERT_ARG(out);
1860
+ GIT_ASSERT_ARG(source);
1861
+
1862
+ GIT_REFCOUNT_INC(source);
1863
+
1864
+ *out = source;
1865
+ return 0;
1866
+ }
1867
+
1801
1868
  void git_submodule_free(git_submodule *sm)
1802
1869
  {
1803
1870
  if (!sm)
@@ -2024,7 +2091,7 @@ static int submodule_load_from_wd_lite(git_submodule *sm)
2024
2091
  {
2025
2092
  git_buf path = GIT_BUF_INIT;
2026
2093
 
2027
- if (git_buf_joinpath(&path, git_repository_workdir(sm->repo), sm->path) < 0)
2094
+ if (git_repository_workdir_path(&path, sm->repo, sm->path) < 0)
2028
2095
  return -1;
2029
2096
 
2030
2097
  if (git_path_isdir(path.ptr))
@@ -2044,15 +2111,14 @@ static int submodule_load_from_wd_lite(git_submodule *sm)
2044
2111
  */
2045
2112
  static int gitmodules_snapshot(git_config **snap, git_repository *repo)
2046
2113
  {
2047
- const char *workdir = git_repository_workdir(repo);
2048
2114
  git_config *mods = NULL;
2049
2115
  git_buf path = GIT_BUF_INIT;
2050
2116
  int error;
2051
2117
 
2052
- if (!workdir)
2118
+ if (git_repository_workdir(repo) == NULL)
2053
2119
  return GIT_ENOTFOUND;
2054
2120
 
2055
- if ((error = git_buf_joinpath(&path, workdir, GIT_MODULES_FILE)) < 0)
2121
+ if ((error = git_repository_workdir_path(&path, repo, GIT_MODULES_FILE)) < 0)
2056
2122
  return error;
2057
2123
 
2058
2124
  if ((error = git_config_open_ondisk(&mods, path.ptr)) < 0)
@@ -2076,12 +2142,11 @@ static git_config_backend *open_gitmodules(
2076
2142
  git_repository *repo,
2077
2143
  int okay_to_create)
2078
2144
  {
2079
- const char *workdir = git_repository_workdir(repo);
2080
2145
  git_buf path = GIT_BUF_INIT;
2081
2146
  git_config_backend *mods = NULL;
2082
2147
 
2083
- if (workdir != NULL) {
2084
- if (git_buf_joinpath(&path, workdir, GIT_MODULES_FILE) != 0)
2148
+ if (git_repository_workdir(repo) != NULL) {
2149
+ if (git_repository_workdir_path(&path, repo, GIT_MODULES_FILE) != 0)
2085
2150
  return NULL;
2086
2151
 
2087
2152
  if (okay_to_create || git_path_isfile(path.ptr)) {
@@ -2194,8 +2259,9 @@ static int get_url_base(git_buf *url, git_repository *repo)
2194
2259
  if ((error = git_worktree_open_from_repository(&wt, repo)) < 0)
2195
2260
  goto out;
2196
2261
  error = git_buf_sets(url, wt->parent_path);
2197
- } else
2262
+ } else {
2198
2263
  error = git_buf_sets(url, git_repository_workdir(repo));
2264
+ }
2199
2265
 
2200
2266
  out:
2201
2267
  git_remote_free(remote);