rugged 1.3.2.3 → 1.4.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (329) hide show
  1. checksums.yaml +4 -4
  2. data/ext/rugged/extconf.rb +1 -1
  3. data/ext/rugged/rugged_config.c +7 -2
  4. data/ext/rugged/rugged_remote.c +17 -0
  5. data/lib/rugged/version.rb +1 -1
  6. data/vendor/libgit2/CMakeLists.txt +103 -276
  7. data/vendor/libgit2/COPYING +36 -19
  8. data/vendor/libgit2/cmake/AddCFlagIfSupported.cmake +21 -21
  9. data/vendor/libgit2/cmake/DefaultCFlags.cmake +154 -0
  10. data/vendor/libgit2/cmake/EnableWarnings.cmake +13 -13
  11. data/vendor/libgit2/cmake/FindCoreFoundation.cmake +13 -13
  12. data/vendor/libgit2/cmake/FindGSSAPI.cmake +171 -287
  13. data/vendor/libgit2/cmake/FindGSSFramework.cmake +13 -13
  14. data/vendor/libgit2/cmake/{FindHTTP_Parser.cmake → FindHTTPParser.cmake} +17 -17
  15. data/vendor/libgit2/cmake/FindIconv.cmake +27 -27
  16. data/vendor/libgit2/cmake/FindLibSSH2.cmake +5 -5
  17. data/vendor/libgit2/cmake/FindPCRE.cmake +13 -13
  18. data/vendor/libgit2/cmake/FindPCRE2.cmake +12 -12
  19. data/vendor/libgit2/cmake/FindPkgLibraries.cmake +19 -19
  20. data/vendor/libgit2/cmake/FindSecurity.cmake +14 -14
  21. data/vendor/libgit2/cmake/FindStatNsec.cmake +12 -18
  22. data/vendor/libgit2/cmake/Findfutimens.cmake +8 -8
  23. data/vendor/libgit2/cmake/FindmbedTLS.cmake +63 -70
  24. data/vendor/libgit2/cmake/IdeSplitSources.cmake +18 -18
  25. data/vendor/libgit2/cmake/PkgBuildConfig.cmake +60 -60
  26. data/vendor/libgit2/cmake/SanitizeBool.cmake +20 -20
  27. data/vendor/libgit2/cmake/SelectGSSAPI.cmake +37 -37
  28. data/vendor/libgit2/cmake/SelectHTTPParser.cmake +19 -0
  29. data/vendor/libgit2/cmake/SelectHTTPSBackend.cmake +100 -100
  30. data/vendor/libgit2/cmake/SelectHashes.cmake +39 -49
  31. data/vendor/libgit2/cmake/SelectRegex.cmake +51 -0
  32. data/vendor/libgit2/cmake/SelectSSH.cmake +41 -0
  33. data/vendor/libgit2/cmake/SelectWinHTTP.cmake +17 -0
  34. data/vendor/libgit2/cmake/SelectZlib.cmake +34 -0
  35. data/vendor/libgit2/deps/chromium-zlib/CMakeLists.txt +6 -6
  36. data/vendor/libgit2/deps/ntlmclient/CMakeLists.txt +31 -31
  37. data/vendor/libgit2/deps/ntlmclient/crypt_openssl.c +1 -1
  38. data/vendor/libgit2/deps/ntlmclient/ntlm.c +4 -4
  39. data/vendor/libgit2/deps/ntlmclient/ntlm.h +4 -4
  40. data/vendor/libgit2/deps/ntlmclient/ntlmclient.h +2 -2
  41. data/vendor/libgit2/deps/pcre/CMakeLists.txt +88 -88
  42. data/vendor/libgit2/deps/winhttp/CMakeLists.txt +14 -16
  43. data/vendor/libgit2/deps/zlib/adler32.c +0 -7
  44. data/vendor/libgit2/deps/zlib/crc32.c +288 -975
  45. data/vendor/libgit2/deps/zlib/crc32.h +436 -9441
  46. data/vendor/libgit2/deps/zlib/deflate.c +31 -83
  47. data/vendor/libgit2/deps/zlib/deflate.h +15 -12
  48. data/vendor/libgit2/deps/zlib/gzguts.h +2 -3
  49. data/vendor/libgit2/deps/zlib/infback.c +1 -2
  50. data/vendor/libgit2/deps/zlib/inffast.c +14 -14
  51. data/vendor/libgit2/deps/zlib/inflate.c +8 -39
  52. data/vendor/libgit2/deps/zlib/inflate.h +2 -3
  53. data/vendor/libgit2/deps/zlib/inftrees.c +3 -3
  54. data/vendor/libgit2/deps/zlib/trees.c +48 -27
  55. data/vendor/libgit2/deps/zlib/zlib.h +100 -126
  56. data/vendor/libgit2/deps/zlib/zutil.c +2 -2
  57. data/vendor/libgit2/deps/zlib/zutil.h +9 -12
  58. data/vendor/libgit2/include/git2/apply.h +16 -2
  59. data/vendor/libgit2/include/git2/attr.h +11 -2
  60. data/vendor/libgit2/include/git2/blame.h +4 -1
  61. data/vendor/libgit2/include/git2/blob.h +14 -1
  62. data/vendor/libgit2/include/git2/branch.h +2 -0
  63. data/vendor/libgit2/include/git2/buffer.h +18 -78
  64. data/vendor/libgit2/include/git2/cert.h +2 -2
  65. data/vendor/libgit2/include/git2/checkout.h +5 -2
  66. data/vendor/libgit2/include/git2/clone.h +3 -3
  67. data/vendor/libgit2/include/git2/commit.h +2 -0
  68. data/vendor/libgit2/include/git2/common.h +5 -12
  69. data/vendor/libgit2/include/git2/config.h +19 -3
  70. data/vendor/libgit2/include/git2/credential.h +2 -1
  71. data/vendor/libgit2/include/git2/credential_helpers.h +1 -0
  72. data/vendor/libgit2/include/git2/deprecated.h +1 -1
  73. data/vendor/libgit2/include/git2/describe.h +7 -2
  74. data/vendor/libgit2/include/git2/diff.h +17 -9
  75. data/vendor/libgit2/include/git2/email.h +1 -1
  76. data/vendor/libgit2/include/git2/errors.h +1 -2
  77. data/vendor/libgit2/include/git2/filter.h +7 -2
  78. data/vendor/libgit2/include/git2/graph.h +1 -0
  79. data/vendor/libgit2/include/git2/ignore.h +1 -1
  80. data/vendor/libgit2/include/git2/index.h +11 -5
  81. data/vendor/libgit2/include/git2/indexer.h +19 -0
  82. data/vendor/libgit2/include/git2/merge.h +23 -3
  83. data/vendor/libgit2/include/git2/message.h +2 -0
  84. data/vendor/libgit2/include/git2/object.h +23 -0
  85. data/vendor/libgit2/include/git2/odb.h +37 -7
  86. data/vendor/libgit2/include/git2/odb_backend.h +1 -1
  87. data/vendor/libgit2/include/git2/pack.h +24 -8
  88. data/vendor/libgit2/include/git2/patch.h +8 -0
  89. data/vendor/libgit2/include/git2/pathspec.h +1 -1
  90. data/vendor/libgit2/include/git2/proxy.h +1 -1
  91. data/vendor/libgit2/include/git2/rebase.h +9 -1
  92. data/vendor/libgit2/include/git2/refdb.h +3 -0
  93. data/vendor/libgit2/include/git2/reflog.h +1 -1
  94. data/vendor/libgit2/include/git2/refs.h +2 -2
  95. data/vendor/libgit2/include/git2/remote.h +184 -37
  96. data/vendor/libgit2/include/git2/repository.h +14 -9
  97. data/vendor/libgit2/include/git2/reset.h +2 -2
  98. data/vendor/libgit2/include/git2/revparse.h +1 -1
  99. data/vendor/libgit2/include/git2/revwalk.h +4 -1
  100. data/vendor/libgit2/include/git2/signature.h +1 -1
  101. data/vendor/libgit2/include/git2/stash.h +3 -3
  102. data/vendor/libgit2/include/git2/status.h +9 -3
  103. data/vendor/libgit2/include/git2/submodule.h +7 -2
  104. data/vendor/libgit2/include/git2/sys/commit_graph.h +1 -1
  105. data/vendor/libgit2/include/git2/sys/odb_backend.h +2 -5
  106. data/vendor/libgit2/include/git2/sys/remote.h +31 -0
  107. data/vendor/libgit2/include/git2/sys/stream.h +1 -1
  108. data/vendor/libgit2/include/git2/sys/transport.h +25 -34
  109. data/vendor/libgit2/include/git2/tag.h +1 -0
  110. data/vendor/libgit2/include/git2/tree.h +4 -3
  111. data/vendor/libgit2/include/git2/types.h +7 -7
  112. data/vendor/libgit2/include/git2/version.h +3 -3
  113. data/vendor/libgit2/include/git2/worktree.h +12 -2
  114. data/vendor/libgit2/src/CMakeLists.txt +189 -315
  115. data/vendor/libgit2/src/annotated_commit.h +1 -1
  116. data/vendor/libgit2/src/apply.c +18 -18
  117. data/vendor/libgit2/src/apply.h +2 -2
  118. data/vendor/libgit2/src/attr.c +18 -18
  119. data/vendor/libgit2/src/attr_file.c +17 -17
  120. data/vendor/libgit2/src/attr_file.h +4 -4
  121. data/vendor/libgit2/src/attrcache.c +17 -12
  122. data/vendor/libgit2/src/blame_git.c +1 -1
  123. data/vendor/libgit2/src/blob.c +33 -26
  124. data/vendor/libgit2/src/blob.h +1 -1
  125. data/vendor/libgit2/src/branch.c +150 -109
  126. data/vendor/libgit2/src/branch.h +15 -3
  127. data/vendor/libgit2/src/buf.c +126 -0
  128. data/vendor/libgit2/src/buf.h +50 -0
  129. data/vendor/libgit2/src/cc-compat.h +1 -1
  130. data/vendor/libgit2/src/checkout.c +74 -68
  131. data/vendor/libgit2/src/cherrypick.c +10 -10
  132. data/vendor/libgit2/src/clone.c +66 -66
  133. data/vendor/libgit2/src/commit.c +128 -58
  134. data/vendor/libgit2/src/commit.h +24 -1
  135. data/vendor/libgit2/src/commit_graph.c +68 -53
  136. data/vendor/libgit2/src/commit_graph.h +10 -3
  137. data/vendor/libgit2/src/commit_list.c +2 -3
  138. data/vendor/libgit2/src/common.h +10 -3
  139. data/vendor/libgit2/src/config.c +99 -77
  140. data/vendor/libgit2/src/config.h +15 -2
  141. data/vendor/libgit2/src/config_file.c +103 -91
  142. data/vendor/libgit2/src/config_mem.c +9 -9
  143. data/vendor/libgit2/src/config_parse.c +27 -23
  144. data/vendor/libgit2/src/crlf.c +24 -21
  145. data/vendor/libgit2/src/date.c +10 -17
  146. data/vendor/libgit2/src/date.h +33 -0
  147. data/vendor/libgit2/src/describe.c +27 -19
  148. data/vendor/libgit2/src/diff.c +25 -8
  149. data/vendor/libgit2/src/diff.h +2 -4
  150. data/vendor/libgit2/src/diff_driver.c +34 -36
  151. data/vendor/libgit2/src/diff_driver.h +3 -3
  152. data/vendor/libgit2/src/diff_file.c +29 -20
  153. data/vendor/libgit2/src/diff_generate.c +30 -6
  154. data/vendor/libgit2/src/diff_generate.h +5 -3
  155. data/vendor/libgit2/src/diff_print.c +102 -95
  156. data/vendor/libgit2/src/diff_stats.c +40 -29
  157. data/vendor/libgit2/src/{message.h → diff_stats.h} +7 -6
  158. data/vendor/libgit2/src/diff_tform.c +9 -8
  159. data/vendor/libgit2/src/diff_xdiff.c +3 -8
  160. data/vendor/libgit2/src/email.c +54 -38
  161. data/vendor/libgit2/src/email.h +1 -1
  162. data/vendor/libgit2/src/errors.c +18 -18
  163. data/vendor/libgit2/src/features.h.in +6 -1
  164. data/vendor/libgit2/src/fetch.c +69 -24
  165. data/vendor/libgit2/src/fetch.h +1 -1
  166. data/vendor/libgit2/src/fetchhead.c +19 -19
  167. data/vendor/libgit2/src/filebuf.c +28 -28
  168. data/vendor/libgit2/src/filebuf.h +1 -1
  169. data/vendor/libgit2/src/filter.c +96 -52
  170. data/vendor/libgit2/src/filter.h +26 -5
  171. data/vendor/libgit2/src/fs_path.c +1912 -0
  172. data/vendor/libgit2/src/fs_path.h +752 -0
  173. data/vendor/libgit2/src/futils.c +91 -85
  174. data/vendor/libgit2/src/futils.h +26 -14
  175. data/vendor/libgit2/src/hash/sha1/collisiondetect.c +2 -2
  176. data/vendor/libgit2/src/hash/sha1/common_crypto.c +2 -2
  177. data/vendor/libgit2/src/hash/sha1/generic.c +2 -2
  178. data/vendor/libgit2/src/hash/sha1/mbedtls.c +2 -2
  179. data/vendor/libgit2/src/hash/sha1/openssl.c +2 -2
  180. data/vendor/libgit2/src/hash/sha1/sha1dc/sha1.c +1 -1
  181. data/vendor/libgit2/src/hash/sha1/win32.c +6 -6
  182. data/vendor/libgit2/src/hash/sha1.h +3 -1
  183. data/vendor/libgit2/src/hash.c +67 -35
  184. data/vendor/libgit2/src/hash.h +12 -12
  185. data/vendor/libgit2/src/ident.c +18 -18
  186. data/vendor/libgit2/src/ignore.c +35 -34
  187. data/vendor/libgit2/src/ignore.h +2 -2
  188. data/vendor/libgit2/src/index.c +79 -80
  189. data/vendor/libgit2/src/index.h +6 -3
  190. data/vendor/libgit2/src/indexer.c +75 -57
  191. data/vendor/libgit2/src/iterator.c +64 -56
  192. data/vendor/libgit2/src/iterator.h +5 -5
  193. data/vendor/libgit2/src/khash.h +1 -1
  194. data/vendor/libgit2/src/libgit2.c +22 -19
  195. data/vendor/libgit2/src/mailmap.c +38 -36
  196. data/vendor/libgit2/src/merge.c +27 -27
  197. data/vendor/libgit2/src/merge.h +1 -14
  198. data/vendor/libgit2/src/merge_driver.c +2 -2
  199. data/vendor/libgit2/src/merge_file.c +13 -3
  200. data/vendor/libgit2/src/message.c +21 -10
  201. data/vendor/libgit2/src/midx.c +83 -66
  202. data/vendor/libgit2/src/midx.h +3 -3
  203. data/vendor/libgit2/src/mwindow.c +1 -1
  204. data/vendor/libgit2/src/net.c +278 -68
  205. data/vendor/libgit2/src/net.h +10 -3
  206. data/vendor/libgit2/src/netops.c +1 -1
  207. data/vendor/libgit2/src/netops.h +1 -1
  208. data/vendor/libgit2/src/notes.c +20 -29
  209. data/vendor/libgit2/src/object.c +49 -9
  210. data/vendor/libgit2/src/object.h +1 -1
  211. data/vendor/libgit2/src/odb.c +35 -32
  212. data/vendor/libgit2/src/odb.h +1 -1
  213. data/vendor/libgit2/src/odb_loose.c +68 -68
  214. data/vendor/libgit2/src/odb_mempack.c +18 -5
  215. data/vendor/libgit2/src/odb_pack.c +43 -43
  216. data/vendor/libgit2/src/oid.c +11 -4
  217. data/vendor/libgit2/src/oid.h +15 -0
  218. data/vendor/libgit2/src/pack-objects.c +41 -26
  219. data/vendor/libgit2/src/pack-objects.h +11 -6
  220. data/vendor/libgit2/src/pack.c +10 -10
  221. data/vendor/libgit2/src/patch.c +3 -3
  222. data/vendor/libgit2/src/patch.h +1 -0
  223. data/vendor/libgit2/src/patch_generate.c +27 -11
  224. data/vendor/libgit2/src/patch_generate.h +5 -5
  225. data/vendor/libgit2/src/patch_parse.c +24 -24
  226. data/vendor/libgit2/src/path.c +76 -1951
  227. data/vendor/libgit2/src/path.h +34 -741
  228. data/vendor/libgit2/src/pathspec.c +6 -6
  229. data/vendor/libgit2/src/pathspec.h +2 -2
  230. data/vendor/libgit2/src/posix.c +3 -3
  231. data/vendor/libgit2/src/posix.h +1 -0
  232. data/vendor/libgit2/src/pqueue.h +1 -1
  233. data/vendor/libgit2/src/proxy.c +4 -1
  234. data/vendor/libgit2/src/proxy.h +1 -1
  235. data/vendor/libgit2/src/push.c +30 -35
  236. data/vendor/libgit2/src/push.h +4 -16
  237. data/vendor/libgit2/src/rand.c +226 -0
  238. data/vendor/libgit2/src/rand.h +37 -0
  239. data/vendor/libgit2/src/reader.c +8 -8
  240. data/vendor/libgit2/src/reader.h +2 -2
  241. data/vendor/libgit2/src/rebase.c +89 -88
  242. data/vendor/libgit2/src/refdb_fs.c +447 -173
  243. data/vendor/libgit2/src/refs.c +32 -32
  244. data/vendor/libgit2/src/refs.h +2 -2
  245. data/vendor/libgit2/src/refspec.c +32 -37
  246. data/vendor/libgit2/src/refspec.h +5 -2
  247. data/vendor/libgit2/src/regexp.c +1 -1
  248. data/vendor/libgit2/src/remote.c +713 -419
  249. data/vendor/libgit2/src/remote.h +15 -10
  250. data/vendor/libgit2/src/repository.c +350 -467
  251. data/vendor/libgit2/src/repository.h +11 -10
  252. data/vendor/libgit2/src/reset.c +8 -5
  253. data/vendor/libgit2/src/revert.c +10 -10
  254. data/vendor/libgit2/src/revparse.c +48 -35
  255. data/vendor/libgit2/src/revwalk.c +7 -7
  256. data/vendor/libgit2/src/signature.c +12 -6
  257. data/vendor/libgit2/src/signature.h +1 -1
  258. data/vendor/libgit2/src/sortedcache.c +1 -1
  259. data/vendor/libgit2/src/sortedcache.h +1 -1
  260. data/vendor/libgit2/src/stash.c +36 -37
  261. data/vendor/libgit2/src/status.c +4 -1
  262. data/vendor/libgit2/src/{buffer.c → str.c} +157 -151
  263. data/vendor/libgit2/src/str.h +357 -0
  264. data/vendor/libgit2/src/streams/mbedtls.c +8 -6
  265. data/vendor/libgit2/src/streams/openssl_dynamic.h +3 -3
  266. data/vendor/libgit2/src/submodule.c +171 -159
  267. data/vendor/libgit2/src/submodule.h +1 -1
  268. data/vendor/libgit2/src/sysdir.c +68 -52
  269. data/vendor/libgit2/src/sysdir.h +15 -10
  270. data/vendor/libgit2/src/tag.c +29 -27
  271. data/vendor/libgit2/src/thread.h +3 -3
  272. data/vendor/libgit2/src/threadstate.c +3 -3
  273. data/vendor/libgit2/src/threadstate.h +1 -1
  274. data/vendor/libgit2/src/trace.c +1 -14
  275. data/vendor/libgit2/src/trace.h +5 -22
  276. data/vendor/libgit2/src/trailer.c +1 -1
  277. data/vendor/libgit2/src/transaction.c +1 -1
  278. data/vendor/libgit2/src/transport.c +10 -10
  279. data/vendor/libgit2/src/transports/auth.c +7 -9
  280. data/vendor/libgit2/src/transports/auth.h +2 -3
  281. data/vendor/libgit2/src/transports/auth_negotiate.c +12 -13
  282. data/vendor/libgit2/src/transports/auth_ntlm.c +10 -10
  283. data/vendor/libgit2/src/transports/auth_ntlm.h +0 -1
  284. data/vendor/libgit2/src/transports/git.c +9 -11
  285. data/vendor/libgit2/src/transports/http.c +37 -17
  286. data/vendor/libgit2/src/transports/http.h +2 -3
  287. data/vendor/libgit2/src/transports/httpclient.c +65 -65
  288. data/vendor/libgit2/src/transports/local.c +124 -116
  289. data/vendor/libgit2/src/transports/smart.c +51 -139
  290. data/vendor/libgit2/src/transports/smart.h +25 -31
  291. data/vendor/libgit2/src/transports/smart_pkt.c +33 -33
  292. data/vendor/libgit2/src/transports/smart_protocol.c +57 -39
  293. data/vendor/libgit2/src/transports/ssh.c +47 -112
  294. data/vendor/libgit2/src/transports/winhttp.c +50 -56
  295. data/vendor/libgit2/src/tree-cache.c +5 -5
  296. data/vendor/libgit2/src/tree-cache.h +2 -2
  297. data/vendor/libgit2/src/tree.c +59 -48
  298. data/vendor/libgit2/src/tree.h +1 -1
  299. data/vendor/libgit2/src/unix/map.c +0 -2
  300. data/vendor/libgit2/src/unix/posix.h +1 -4
  301. data/vendor/libgit2/src/unix/realpath.c +0 -2
  302. data/vendor/libgit2/src/util.c +14 -14
  303. data/vendor/libgit2/src/util.h +2 -28
  304. data/vendor/libgit2/src/vector.h +1 -1
  305. data/vendor/libgit2/src/win32/findfile.c +172 -116
  306. data/vendor/libgit2/src/win32/findfile.h +7 -4
  307. data/vendor/libgit2/src/win32/path_w32.c +140 -9
  308. data/vendor/libgit2/src/win32/path_w32.h +2 -0
  309. data/vendor/libgit2/src/win32/posix.h +0 -1
  310. data/vendor/libgit2/src/win32/posix_w32.c +11 -27
  311. data/vendor/libgit2/src/win32/w32_buffer.c +2 -3
  312. data/vendor/libgit2/src/win32/w32_buffer.h +2 -3
  313. data/vendor/libgit2/src/win32/w32_leakcheck.c +1 -1
  314. data/vendor/libgit2/src/worktree.c +116 -94
  315. data/vendor/libgit2/src/worktree.h +1 -1
  316. data/vendor/libgit2/src/xdiff/git-xdiff.h +53 -0
  317. data/vendor/libgit2/src/xdiff/xdiff.h +15 -15
  318. data/vendor/libgit2/src/xdiff/xdiffi.c +134 -108
  319. data/vendor/libgit2/src/xdiff/xemit.c +23 -7
  320. data/vendor/libgit2/src/xdiff/xhistogram.c +87 -78
  321. data/vendor/libgit2/src/xdiff/xinclude.h +1 -12
  322. data/vendor/libgit2/src/xdiff/xmerge.c +104 -117
  323. data/vendor/libgit2/src/xdiff/xpatience.c +6 -17
  324. data/vendor/libgit2/src/xdiff/xprepare.c +15 -20
  325. data/vendor/libgit2/src/xdiff/xutils.c +18 -7
  326. data/vendor/libgit2/src/zstream.c +5 -5
  327. data/vendor/libgit2/src/zstream.h +4 -4
  328. metadata +25 -10
  329. data/vendor/libgit2/src/buffer.h +0 -374
@@ -9,10 +9,9 @@
9
9
  #include "netops.h"
10
10
 
11
11
  #include <ctype.h>
12
- #include "git2/errors.h"
13
12
 
14
13
  #include "posix.h"
15
- #include "buffer.h"
14
+ #include "str.h"
16
15
  #include "http_parser.h"
17
16
  #include "runtime.h"
18
17
 
@@ -21,6 +20,24 @@
21
20
  #define DEFAULT_PORT_GIT "9418"
22
21
  #define DEFAULT_PORT_SSH "22"
23
22
 
23
+ bool git_net_str_is_url(const char *str)
24
+ {
25
+ const char *c;
26
+
27
+ for (c = str; *c; c++) {
28
+ if (*c == ':' && *(c+1) == '/' && *(c+2) == '/')
29
+ return true;
30
+
31
+ if ((*c < 'a' || *c > 'z') &&
32
+ (*c < 'A' || *c > 'Z') &&
33
+ (*c < '0' || *c > '9') &&
34
+ (*c != '+' && *c != '-' && *c != '.'))
35
+ break;
36
+ }
37
+
38
+ return false;
39
+ }
40
+
24
41
  static const char *default_port_for_scheme(const char *scheme)
25
42
  {
26
43
  if (strcmp(scheme, "http") == 0)
@@ -29,7 +46,9 @@ static const char *default_port_for_scheme(const char *scheme)
29
46
  return DEFAULT_PORT_HTTPS;
30
47
  else if (strcmp(scheme, "git") == 0)
31
48
  return DEFAULT_PORT_GIT;
32
- else if (strcmp(scheme, "ssh") == 0)
49
+ else if (strcmp(scheme, "ssh") == 0 ||
50
+ strcmp(scheme, "ssh+git") == 0 ||
51
+ strcmp(scheme, "git+ssh") == 0)
33
52
  return DEFAULT_PORT_SSH;
34
53
 
35
54
  return NULL;
@@ -79,13 +98,13 @@ int git_net_url_parse(git_net_url *url, const char *given)
79
98
  {
80
99
  struct http_parser_url u = {0};
81
100
  bool has_scheme, has_host, has_port, has_path, has_query, has_userinfo;
82
- git_buf scheme = GIT_BUF_INIT,
83
- host = GIT_BUF_INIT,
84
- port = GIT_BUF_INIT,
85
- path = GIT_BUF_INIT,
86
- username = GIT_BUF_INIT,
87
- password = GIT_BUF_INIT,
88
- query = GIT_BUF_INIT;
101
+ git_str scheme = GIT_STR_INIT,
102
+ host = GIT_STR_INIT,
103
+ port = GIT_STR_INIT,
104
+ path = GIT_STR_INIT,
105
+ username = GIT_STR_INIT,
106
+ password = GIT_STR_INIT,
107
+ query = GIT_STR_INIT;
89
108
  int error = GIT_EINVALIDSPEC;
90
109
 
91
110
  if (http_parser_parse_url(given, strlen(given), false, &u)) {
@@ -103,7 +122,7 @@ int git_net_url_parse(git_net_url *url, const char *given)
103
122
  if (has_scheme) {
104
123
  const char *url_scheme = given + u.field_data[UF_SCHEMA].off;
105
124
  size_t url_scheme_len = u.field_data[UF_SCHEMA].len;
106
- git_buf_put(&scheme, url_scheme, url_scheme_len);
125
+ git_str_put(&scheme, url_scheme, url_scheme_len);
107
126
  git__strntolower(scheme.ptr, scheme.size);
108
127
  } else {
109
128
  git_error_set(GIT_ERROR_NET, "malformed URL '%s'", given);
@@ -113,13 +132,13 @@ int git_net_url_parse(git_net_url *url, const char *given)
113
132
  if (has_host) {
114
133
  const char *url_host = given + u.field_data[UF_HOST].off;
115
134
  size_t url_host_len = u.field_data[UF_HOST].len;
116
- git_buf_decode_percent(&host, url_host, url_host_len);
135
+ git_str_decode_percent(&host, url_host, url_host_len);
117
136
  }
118
137
 
119
138
  if (has_port) {
120
139
  const char *url_port = given + u.field_data[UF_PORT].off;
121
140
  size_t url_port_len = u.field_data[UF_PORT].len;
122
- git_buf_put(&port, url_port, url_port_len);
141
+ git_str_put(&port, url_port, url_port_len);
123
142
  } else {
124
143
  const char *default_port = default_port_for_scheme(scheme.ptr);
125
144
 
@@ -128,21 +147,21 @@ int git_net_url_parse(git_net_url *url, const char *given)
128
147
  goto done;
129
148
  }
130
149
 
131
- git_buf_puts(&port, default_port);
150
+ git_str_puts(&port, default_port);
132
151
  }
133
152
 
134
153
  if (has_path) {
135
154
  const char *url_path = given + u.field_data[UF_PATH].off;
136
155
  size_t url_path_len = u.field_data[UF_PATH].len;
137
- git_buf_put(&path, url_path, url_path_len);
156
+ git_str_put(&path, url_path, url_path_len);
138
157
  } else {
139
- git_buf_puts(&path, "/");
158
+ git_str_puts(&path, "/");
140
159
  }
141
160
 
142
161
  if (has_query) {
143
162
  const char *url_query = given + u.field_data[UF_QUERY].off;
144
163
  size_t url_query_len = u.field_data[UF_QUERY].len;
145
- git_buf_decode_percent(&query, url_query, url_query_len);
164
+ git_str_decode_percent(&query, url_query, url_query_len);
146
165
  }
147
166
 
148
167
  if (has_userinfo) {
@@ -156,49 +175,238 @@ int git_net_url_parse(git_net_url *url, const char *given)
156
175
  const char *url_password = colon + 1;
157
176
  size_t url_password_len = url_userinfo_len - (url_username_len + 1);
158
177
 
159
- git_buf_decode_percent(&username, url_username, url_username_len);
160
- git_buf_decode_percent(&password, url_password, url_password_len);
178
+ git_str_decode_percent(&username, url_username, url_username_len);
179
+ git_str_decode_percent(&password, url_password, url_password_len);
161
180
  } else {
162
- git_buf_decode_percent(&username, url_userinfo, url_userinfo_len);
181
+ git_str_decode_percent(&username, url_userinfo, url_userinfo_len);
163
182
  }
164
183
  }
165
184
 
166
- if (git_buf_oom(&scheme) ||
167
- git_buf_oom(&host) ||
168
- git_buf_oom(&port) ||
169
- git_buf_oom(&path) ||
170
- git_buf_oom(&query) ||
171
- git_buf_oom(&username) ||
172
- git_buf_oom(&password))
185
+ if (git_str_oom(&scheme) ||
186
+ git_str_oom(&host) ||
187
+ git_str_oom(&port) ||
188
+ git_str_oom(&path) ||
189
+ git_str_oom(&query) ||
190
+ git_str_oom(&username) ||
191
+ git_str_oom(&password))
173
192
  return -1;
174
193
 
175
- url->scheme = git_buf_detach(&scheme);
176
- url->host = git_buf_detach(&host);
177
- url->port = git_buf_detach(&port);
178
- url->path = git_buf_detach(&path);
179
- url->query = git_buf_detach(&query);
180
- url->username = git_buf_detach(&username);
181
- url->password = git_buf_detach(&password);
194
+ url->scheme = git_str_detach(&scheme);
195
+ url->host = git_str_detach(&host);
196
+ url->port = git_str_detach(&port);
197
+ url->path = git_str_detach(&path);
198
+ url->query = git_str_detach(&query);
199
+ url->username = git_str_detach(&username);
200
+ url->password = git_str_detach(&password);
182
201
 
183
202
  error = 0;
184
203
 
185
204
  done:
186
- git_buf_dispose(&scheme);
187
- git_buf_dispose(&host);
188
- git_buf_dispose(&port);
189
- git_buf_dispose(&path);
190
- git_buf_dispose(&query);
191
- git_buf_dispose(&username);
192
- git_buf_dispose(&password);
205
+ git_str_dispose(&scheme);
206
+ git_str_dispose(&host);
207
+ git_str_dispose(&port);
208
+ git_str_dispose(&path);
209
+ git_str_dispose(&query);
210
+ git_str_dispose(&username);
211
+ git_str_dispose(&password);
193
212
  return error;
194
213
  }
195
214
 
215
+ static int scp_invalid(const char *message)
216
+ {
217
+ git_error_set(GIT_ERROR_NET, "invalid scp-style path: %s", message);
218
+ return GIT_EINVALIDSPEC;
219
+ }
220
+
221
+ static bool is_ipv6(const char *str)
222
+ {
223
+ const char *c;
224
+ size_t colons = 0;
225
+
226
+ if (*str++ != '[')
227
+ return false;
228
+
229
+ for (c = str; *c; c++) {
230
+ if (*c == ':')
231
+ colons++;
232
+
233
+ if (*c == ']')
234
+ return (colons > 1);
235
+
236
+ if (*c != ':' &&
237
+ (*c < '0' || *c > '9') &&
238
+ (*c < 'a' || *c > 'f') &&
239
+ (*c < 'A' || *c > 'F'))
240
+ return false;
241
+ }
242
+
243
+ return false;
244
+ }
245
+
246
+ static bool has_at(const char *str)
247
+ {
248
+ const char *c;
249
+
250
+ for (c = str; *c; c++) {
251
+ if (*c == '@')
252
+ return true;
253
+
254
+ if (*c == ':')
255
+ break;
256
+ }
257
+
258
+ return false;
259
+ }
260
+
261
+ int git_net_url_parse_scp(git_net_url *url, const char *given)
262
+ {
263
+ const char *default_port = default_port_for_scheme("ssh");
264
+ const char *c, *user, *host, *port, *path = NULL;
265
+ size_t user_len = 0, host_len = 0, port_len = 0;
266
+ unsigned short bracket = 0;
267
+
268
+ enum {
269
+ NONE,
270
+ USER,
271
+ HOST_START, HOST, HOST_END,
272
+ IPV6, IPV6_END,
273
+ PORT_START, PORT, PORT_END,
274
+ PATH_START
275
+ } state = NONE;
276
+
277
+ memset(url, 0, sizeof(git_net_url));
278
+
279
+ for (c = given; *c && !path; c++) {
280
+ switch (state) {
281
+ case NONE:
282
+ switch (*c) {
283
+ case '@':
284
+ return scp_invalid("unexpected '@'");
285
+ case ':':
286
+ return scp_invalid("unexpected ':'");
287
+ case '[':
288
+ if (is_ipv6(c)) {
289
+ state = IPV6;
290
+ host = c;
291
+ } else if (bracket++ > 1) {
292
+ return scp_invalid("unexpected '['");
293
+ }
294
+ break;
295
+ default:
296
+ if (has_at(c)) {
297
+ state = USER;
298
+ user = c;
299
+ } else {
300
+ state = HOST;
301
+ host = c;
302
+ }
303
+ break;
304
+ }
305
+ break;
306
+
307
+ case USER:
308
+ if (*c == '@') {
309
+ user_len = (c - user);
310
+ state = HOST_START;
311
+ }
312
+ break;
313
+
314
+ case HOST_START:
315
+ state = (*c == '[') ? IPV6 : HOST;
316
+ host = c;
317
+ break;
318
+
319
+ case HOST:
320
+ if (*c == ':') {
321
+ host_len = (c - host);
322
+ state = bracket ? PORT_START : PATH_START;
323
+ } else if (*c == ']') {
324
+ if (bracket-- == 0)
325
+ return scp_invalid("unexpected ']'");
326
+
327
+ host_len = (c - host);
328
+ state = HOST_END;
329
+ }
330
+ break;
331
+
332
+ case HOST_END:
333
+ if (*c != ':')
334
+ return scp_invalid("unexpected character after hostname");
335
+ state = PATH_START;
336
+ break;
337
+
338
+ case IPV6:
339
+ if (*c == ']')
340
+ state = IPV6_END;
341
+ break;
342
+
343
+ case IPV6_END:
344
+ if (*c != ':')
345
+ return scp_invalid("unexpected character after ipv6 address");
346
+
347
+ host_len = (c - host);
348
+ state = bracket ? PORT_START : PATH_START;
349
+ break;
350
+
351
+ case PORT_START:
352
+ port = c;
353
+ state = PORT;
354
+ break;
355
+
356
+ case PORT:
357
+ if (*c == ']') {
358
+ if (bracket-- == 0)
359
+ return scp_invalid("unexpected ']'");
360
+
361
+ port_len = c - port;
362
+ state = PORT_END;
363
+ }
364
+ break;
365
+
366
+ case PORT_END:
367
+ if (*c != ':')
368
+ return scp_invalid("unexpected character after ipv6 address");
369
+
370
+ state = PATH_START;
371
+ break;
372
+
373
+ case PATH_START:
374
+ path = c;
375
+ break;
376
+
377
+ default:
378
+ GIT_ASSERT("unhandled state");
379
+ }
380
+ }
381
+
382
+ if (!path)
383
+ return scp_invalid("path is required");
384
+
385
+ GIT_ERROR_CHECK_ALLOC(url->scheme = git__strdup("ssh"));
386
+
387
+ if (user_len)
388
+ GIT_ERROR_CHECK_ALLOC(url->username = git__strndup(user, user_len));
389
+
390
+ GIT_ASSERT(host_len);
391
+ GIT_ERROR_CHECK_ALLOC(url->host = git__strndup(host, host_len));
392
+
393
+ if (port_len)
394
+ GIT_ERROR_CHECK_ALLOC(url->port = git__strndup(port, port_len));
395
+ else
396
+ GIT_ERROR_CHECK_ALLOC(url->port = git__strdup(default_port));
397
+
398
+ GIT_ASSERT(path);
399
+ GIT_ERROR_CHECK_ALLOC(url->path = git__strdup(path));
400
+
401
+ return 0;
402
+ }
403
+
196
404
  int git_net_url_joinpath(
197
405
  git_net_url *out,
198
406
  git_net_url *one,
199
407
  const char *two)
200
408
  {
201
- git_buf path = GIT_BUF_INIT;
409
+ git_str path = GIT_STR_INIT;
202
410
  const char *query;
203
411
  size_t one_len, two_len;
204
412
 
@@ -226,14 +434,14 @@ int git_net_url_joinpath(
226
434
  two_len--;
227
435
  }
228
436
 
229
- git_buf_put(&path, one->path, one_len);
230
- git_buf_putc(&path, '/');
231
- git_buf_put(&path, two, two_len);
437
+ git_str_put(&path, one->path, one_len);
438
+ git_str_putc(&path, '/');
439
+ git_str_put(&path, two, two_len);
232
440
 
233
- if (git_buf_oom(&path))
441
+ if (git_str_oom(&path))
234
442
  return -1;
235
443
 
236
- out->path = git_buf_detach(&path);
444
+ out->path = git_str_detach(&path);
237
445
 
238
446
  if (one->scheme) {
239
447
  out->scheme = git__strdup(one->scheme);
@@ -316,6 +524,7 @@ static void remove_service_suffix(
316
524
  int git_net_url_apply_redirect(
317
525
  git_net_url *url,
318
526
  const char *redirect_location,
527
+ bool allow_offsite,
319
528
  const char *service_suffix)
320
529
  {
321
530
  git_net_url tmp = GIT_NET_URL_INIT;
@@ -340,8 +549,8 @@ int git_net_url_apply_redirect(
340
549
  /* Validate that this is a legal redirection */
341
550
 
342
551
  if (original->scheme &&
343
- strcmp(original->scheme, tmp.scheme) != 0 &&
344
- strcmp(tmp.scheme, "https") != 0) {
552
+ strcmp(original->scheme, tmp.scheme) != 0 &&
553
+ strcmp(tmp.scheme, "https") != 0) {
345
554
  git_error_set(GIT_ERROR_NET, "cannot redirect from '%s' to '%s'",
346
555
  original->scheme, tmp.scheme);
347
556
 
@@ -350,6 +559,7 @@ int git_net_url_apply_redirect(
350
559
  }
351
560
 
352
561
  if (original->host &&
562
+ !allow_offsite &&
353
563
  git__strcasecmp(original->host, tmp.host) != 0) {
354
564
  git_error_set(GIT_ERROR_NET, "cannot redirect from '%s' to '%s'",
355
565
  original->host, tmp.host);
@@ -399,53 +609,53 @@ void git_net_url_swap(git_net_url *a, git_net_url *b)
399
609
  memcpy(b, &tmp, sizeof(git_net_url));
400
610
  }
401
611
 
402
- int git_net_url_fmt(git_buf *buf, git_net_url *url)
612
+ int git_net_url_fmt(git_str *buf, git_net_url *url)
403
613
  {
404
614
  GIT_ASSERT_ARG(url);
405
615
  GIT_ASSERT_ARG(url->scheme);
406
616
  GIT_ASSERT_ARG(url->host);
407
617
 
408
- git_buf_puts(buf, url->scheme);
409
- git_buf_puts(buf, "://");
618
+ git_str_puts(buf, url->scheme);
619
+ git_str_puts(buf, "://");
410
620
 
411
621
  if (url->username) {
412
- git_buf_puts(buf, url->username);
622
+ git_str_puts(buf, url->username);
413
623
 
414
624
  if (url->password) {
415
- git_buf_puts(buf, ":");
416
- git_buf_puts(buf, url->password);
625
+ git_str_puts(buf, ":");
626
+ git_str_puts(buf, url->password);
417
627
  }
418
628
 
419
- git_buf_putc(buf, '@');
629
+ git_str_putc(buf, '@');
420
630
  }
421
631
 
422
- git_buf_puts(buf, url->host);
632
+ git_str_puts(buf, url->host);
423
633
 
424
634
  if (url->port && !git_net_url_is_default_port(url)) {
425
- git_buf_putc(buf, ':');
426
- git_buf_puts(buf, url->port);
635
+ git_str_putc(buf, ':');
636
+ git_str_puts(buf, url->port);
427
637
  }
428
638
 
429
- git_buf_puts(buf, url->path ? url->path : "/");
639
+ git_str_puts(buf, url->path ? url->path : "/");
430
640
 
431
641
  if (url->query) {
432
- git_buf_putc(buf, '?');
433
- git_buf_puts(buf, url->query);
642
+ git_str_putc(buf, '?');
643
+ git_str_puts(buf, url->query);
434
644
  }
435
645
 
436
- return git_buf_oom(buf) ? -1 : 0;
646
+ return git_str_oom(buf) ? -1 : 0;
437
647
  }
438
648
 
439
- int git_net_url_fmt_path(git_buf *buf, git_net_url *url)
649
+ int git_net_url_fmt_path(git_str *buf, git_net_url *url)
440
650
  {
441
- git_buf_puts(buf, url->path ? url->path : "/");
651
+ git_str_puts(buf, url->path ? url->path : "/");
442
652
 
443
653
  if (url->query) {
444
- git_buf_putc(buf, '?');
445
- git_buf_puts(buf, url->query);
654
+ git_str_putc(buf, '?');
655
+ git_str_puts(buf, url->query);
446
656
  }
447
657
 
448
- return git_buf_oom(buf) ? -1 : 0;
658
+ return git_str_oom(buf) ? -1 : 0;
449
659
  }
450
660
 
451
661
  static bool matches_pattern(
@@ -21,12 +21,18 @@ typedef struct git_net_url {
21
21
 
22
22
  #define GIT_NET_URL_INIT { NULL }
23
23
 
24
+ /** Is a given string a url? */
25
+ extern bool git_net_str_is_url(const char *str);
26
+
24
27
  /** Duplicate a URL */
25
28
  extern int git_net_url_dup(git_net_url *out, git_net_url *in);
26
29
 
27
- /** Parses a string containing a URL into a structure. */
30
+ /** Parses a string containing a URL into a structure. */
28
31
  extern int git_net_url_parse(git_net_url *url, const char *str);
29
32
 
33
+ /** Parses a string containing an SCP style path into a URL structure. */
34
+ extern int git_net_url_parse_scp(git_net_url *url, const char *str);
35
+
30
36
  /** Appends a path and/or query string to the given URL */
31
37
  extern int git_net_url_joinpath(
32
38
  git_net_url *out,
@@ -46,16 +52,17 @@ extern bool git_net_url_is_ipv6(git_net_url *url);
46
52
  extern int git_net_url_apply_redirect(
47
53
  git_net_url *url,
48
54
  const char *redirect_location,
55
+ bool allow_offsite,
49
56
  const char *service_suffix);
50
57
 
51
58
  /** Swaps the contents of one URL for another. */
52
59
  extern void git_net_url_swap(git_net_url *a, git_net_url *b);
53
60
 
54
61
  /** Places the URL into the given buffer. */
55
- extern int git_net_url_fmt(git_buf *out, git_net_url *url);
62
+ extern int git_net_url_fmt(git_str *out, git_net_url *url);
56
63
 
57
64
  /** Place the path and query string into the given buffer. */
58
- extern int git_net_url_fmt_path(git_buf *buf, git_net_url *url);
65
+ extern int git_net_url_fmt_path(git_str *buf, git_net_url *url);
59
66
 
60
67
  /** Determines if the url matches given pattern or pattern list */
61
68
  extern bool git_net_url_matches_pattern(
@@ -11,7 +11,7 @@
11
11
  #include "git2/errors.h"
12
12
 
13
13
  #include "posix.h"
14
- #include "buffer.h"
14
+ #include "str.h"
15
15
  #include "http_parser.h"
16
16
  #include "runtime.h"
17
17
 
@@ -42,7 +42,7 @@ typedef struct gitno_buffer {
42
42
  /* Flags to gitno_connect */
43
43
  enum {
44
44
  /* Attempt to create an SSL connection. */
45
- GITNO_CONNECT_SSL = 1,
45
+ GITNO_CONNECT_SSL = 1
46
46
  };
47
47
 
48
48
  /**