rugged 1.3.1 → 1.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (656) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +34 -2
  3. data/ext/rugged/extconf.rb +6 -3
  4. data/ext/rugged/rugged.c +16 -0
  5. data/ext/rugged/rugged.h +4 -0
  6. data/ext/rugged/rugged_allocator.c +0 -54
  7. data/ext/rugged/rugged_blame.c +2 -0
  8. data/ext/rugged/rugged_blob.c +3 -0
  9. data/ext/rugged/rugged_commit.c +1 -0
  10. data/ext/rugged/rugged_config.c +9 -2
  11. data/ext/rugged/rugged_diff.c +1 -0
  12. data/ext/rugged/rugged_index.c +2 -0
  13. data/ext/rugged/rugged_patch.c +1 -0
  14. data/ext/rugged/rugged_rebase.c +1 -0
  15. data/ext/rugged/rugged_reference.c +1 -0
  16. data/ext/rugged/rugged_remote.c +28 -10
  17. data/ext/rugged/rugged_repo.c +7 -9
  18. data/ext/rugged/rugged_revwalk.c +5 -1
  19. data/ext/rugged/rugged_settings.c +5 -0
  20. data/ext/rugged/rugged_submodule.c +1 -0
  21. data/ext/rugged/rugged_tag.c +1 -0
  22. data/ext/rugged/rugged_tree.c +4 -0
  23. data/lib/rugged/index.rb +1 -1
  24. data/lib/rugged/tree.rb +5 -1
  25. data/lib/rugged/version.rb +1 -1
  26. data/vendor/libgit2/AUTHORS +1 -0
  27. data/vendor/libgit2/CMakeLists.txt +141 -289
  28. data/vendor/libgit2/COPYING +301 -20
  29. data/vendor/libgit2/cmake/AddCFlagIfSupported.cmake +21 -21
  30. data/vendor/libgit2/cmake/AddClarTest.cmake +7 -0
  31. data/vendor/libgit2/cmake/CheckPrototypeDefinitionSafe.cmake +16 -0
  32. data/vendor/libgit2/cmake/DefaultCFlags.cmake +154 -0
  33. data/vendor/libgit2/cmake/EnableWarnings.cmake +13 -13
  34. data/vendor/libgit2/cmake/ExperimentalFeatures.cmake +23 -0
  35. data/vendor/libgit2/cmake/FindCoreFoundation.cmake +13 -13
  36. data/vendor/libgit2/cmake/FindGSSAPI.cmake +171 -287
  37. data/vendor/libgit2/cmake/FindGSSFramework.cmake +13 -13
  38. data/vendor/libgit2/cmake/FindHTTP_Parser.cmake +17 -17
  39. data/vendor/libgit2/cmake/FindIntlIconv.cmake +51 -0
  40. data/vendor/libgit2/cmake/FindLLHTTP.cmake +39 -0
  41. data/vendor/libgit2/cmake/FindLibSSH2.cmake +5 -5
  42. data/vendor/libgit2/cmake/FindPCRE.cmake +12 -13
  43. data/vendor/libgit2/cmake/FindPCRE2.cmake +12 -12
  44. data/vendor/libgit2/cmake/FindPkgLibraries.cmake +19 -19
  45. data/vendor/libgit2/cmake/FindSecurity.cmake +14 -14
  46. data/vendor/libgit2/cmake/FindStatNsec.cmake +12 -18
  47. data/vendor/libgit2/cmake/Findfutimens.cmake +8 -8
  48. data/vendor/libgit2/cmake/FindmbedTLS.cmake +63 -70
  49. data/vendor/libgit2/cmake/IdeSplitSources.cmake +18 -18
  50. data/vendor/libgit2/cmake/PkgBuildConfig.cmake +60 -60
  51. data/vendor/libgit2/cmake/SanitizeBool.cmake +20 -20
  52. data/vendor/libgit2/cmake/SelectGSSAPI.cmake +37 -37
  53. data/vendor/libgit2/cmake/SelectHTTPParser.cmake +34 -0
  54. data/vendor/libgit2/cmake/SelectHTTPSBackend.cmake +129 -101
  55. data/vendor/libgit2/cmake/SelectHashes.cmake +113 -54
  56. data/vendor/libgit2/cmake/SelectRegex.cmake +56 -0
  57. data/vendor/libgit2/cmake/SelectSSH.cmake +46 -0
  58. data/vendor/libgit2/cmake/SelectXdiff.cmake +9 -0
  59. data/vendor/libgit2/cmake/SelectZlib.cmake +38 -0
  60. data/vendor/libgit2/deps/chromium-zlib/CMakeLists.txt +6 -6
  61. data/vendor/libgit2/deps/llhttp/CMakeLists.txt +8 -0
  62. data/vendor/libgit2/deps/llhttp/LICENSE-MIT +22 -0
  63. data/vendor/libgit2/deps/llhttp/api.c +510 -0
  64. data/vendor/libgit2/deps/llhttp/http.c +170 -0
  65. data/vendor/libgit2/deps/llhttp/llhttp.c +10168 -0
  66. data/vendor/libgit2/deps/llhttp/llhttp.h +897 -0
  67. data/vendor/libgit2/deps/ntlmclient/CMakeLists.txt +33 -31
  68. data/vendor/libgit2/deps/ntlmclient/crypt_builtin_md4.c +311 -0
  69. data/vendor/libgit2/deps/ntlmclient/crypt_commoncrypto.c +2 -1
  70. data/vendor/libgit2/deps/ntlmclient/crypt_mbedtls.c +0 -20
  71. data/vendor/libgit2/deps/ntlmclient/crypt_openssl.c +7 -5
  72. data/vendor/libgit2/deps/ntlmclient/ntlm.c +25 -25
  73. data/vendor/libgit2/deps/ntlmclient/ntlm.h +4 -4
  74. data/vendor/libgit2/deps/ntlmclient/ntlmclient.h +2 -2
  75. data/vendor/libgit2/deps/ntlmclient/unicode_builtin.c +5 -4
  76. data/vendor/libgit2/deps/ntlmclient/unicode_iconv.c +2 -1
  77. data/vendor/libgit2/deps/ntlmclient/utf8.h +1176 -721
  78. data/vendor/libgit2/deps/ntlmclient/util.h +11 -0
  79. data/vendor/libgit2/deps/pcre/CMakeLists.txt +89 -88
  80. data/vendor/libgit2/deps/pcre/LICENCE +5 -5
  81. data/vendor/libgit2/deps/pcre/pcre.h +2 -2
  82. data/vendor/libgit2/deps/pcre/pcre_compile.c +6 -3
  83. data/vendor/libgit2/deps/pcre/pcre_exec.c +2 -2
  84. data/vendor/libgit2/deps/winhttp/CMakeLists.txt +14 -16
  85. data/vendor/libgit2/deps/xdiff/CMakeLists.txt +28 -0
  86. data/vendor/libgit2/deps/xdiff/git-xdiff.h +56 -0
  87. data/vendor/libgit2/{src → deps}/xdiff/xdiff.h +15 -15
  88. data/vendor/libgit2/{src → deps}/xdiff/xdiffi.c +152 -125
  89. data/vendor/libgit2/{src → deps}/xdiff/xdiffi.h +2 -4
  90. data/vendor/libgit2/{src → deps}/xdiff/xemit.c +26 -10
  91. data/vendor/libgit2/{src → deps}/xdiff/xhistogram.c +92 -94
  92. data/vendor/libgit2/{src → deps}/xdiff/xinclude.h +1 -12
  93. data/vendor/libgit2/{src → deps}/xdiff/xmacros.h +18 -1
  94. data/vendor/libgit2/{src → deps}/xdiff/xmerge.c +126 -137
  95. data/vendor/libgit2/{src → deps}/xdiff/xpatience.c +26 -46
  96. data/vendor/libgit2/{src → deps}/xdiff/xprepare.c +24 -46
  97. data/vendor/libgit2/{src → deps}/xdiff/xutils.c +36 -8
  98. data/vendor/libgit2/{src → deps}/xdiff/xutils.h +2 -1
  99. data/vendor/libgit2/deps/zlib/CMakeLists.txt +6 -1
  100. data/vendor/libgit2/deps/zlib/LICENSE +22 -0
  101. data/vendor/libgit2/deps/zlib/adler32.c +7 -22
  102. data/vendor/libgit2/deps/zlib/crc32.c +931 -317
  103. data/vendor/libgit2/deps/zlib/crc32.h +9441 -436
  104. data/vendor/libgit2/deps/zlib/deflate.c +428 -453
  105. data/vendor/libgit2/deps/zlib/deflate.h +51 -23
  106. data/vendor/libgit2/deps/zlib/gzguts.h +15 -19
  107. data/vendor/libgit2/deps/zlib/infback.c +19 -31
  108. data/vendor/libgit2/deps/zlib/inffast.c +15 -18
  109. data/vendor/libgit2/deps/zlib/inffast.h +1 -1
  110. data/vendor/libgit2/deps/zlib/inflate.c +75 -110
  111. data/vendor/libgit2/deps/zlib/inflate.h +3 -2
  112. data/vendor/libgit2/deps/zlib/inftrees.c +6 -11
  113. data/vendor/libgit2/deps/zlib/inftrees.h +6 -6
  114. data/vendor/libgit2/deps/zlib/trees.c +294 -380
  115. data/vendor/libgit2/deps/zlib/zconf.h +23 -14
  116. data/vendor/libgit2/deps/zlib/zlib.h +310 -284
  117. data/vendor/libgit2/deps/zlib/zutil.c +20 -46
  118. data/vendor/libgit2/deps/zlib/zutil.h +24 -41
  119. data/vendor/libgit2/include/git2/annotated_commit.h +12 -5
  120. data/vendor/libgit2/include/git2/apply.h +43 -8
  121. data/vendor/libgit2/include/git2/attr.h +28 -6
  122. data/vendor/libgit2/include/git2/blame.h +137 -29
  123. data/vendor/libgit2/include/git2/blob.h +85 -29
  124. data/vendor/libgit2/include/git2/branch.h +25 -16
  125. data/vendor/libgit2/include/git2/buffer.h +24 -82
  126. data/vendor/libgit2/include/git2/cert.h +4 -3
  127. data/vendor/libgit2/include/git2/checkout.h +88 -34
  128. data/vendor/libgit2/include/git2/cherrypick.h +10 -3
  129. data/vendor/libgit2/include/git2/clone.h +28 -12
  130. data/vendor/libgit2/include/git2/commit.h +134 -3
  131. data/vendor/libgit2/include/git2/common.h +172 -59
  132. data/vendor/libgit2/include/git2/config.h +118 -32
  133. data/vendor/libgit2/include/git2/credential.h +32 -3
  134. data/vendor/libgit2/include/git2/credential_helpers.h +2 -0
  135. data/vendor/libgit2/include/git2/deprecated.h +141 -3
  136. data/vendor/libgit2/include/git2/describe.h +20 -3
  137. data/vendor/libgit2/include/git2/diff.h +95 -19
  138. data/vendor/libgit2/include/git2/email.h +10 -30
  139. data/vendor/libgit2/include/git2/errors.h +51 -61
  140. data/vendor/libgit2/include/git2/experimental.h +20 -0
  141. data/vendor/libgit2/include/git2/filter.h +21 -9
  142. data/vendor/libgit2/include/git2/global.h +8 -1
  143. data/vendor/libgit2/include/git2/graph.h +4 -2
  144. data/vendor/libgit2/include/git2/ignore.h +11 -1
  145. data/vendor/libgit2/include/git2/index.h +111 -11
  146. data/vendor/libgit2/include/git2/indexer.h +67 -2
  147. data/vendor/libgit2/include/git2/mailmap.h +7 -1
  148. data/vendor/libgit2/include/git2/merge.h +70 -5
  149. data/vendor/libgit2/include/git2/message.h +4 -2
  150. data/vendor/libgit2/include/git2/net.h +3 -1
  151. data/vendor/libgit2/include/git2/notes.h +9 -6
  152. data/vendor/libgit2/include/git2/object.h +57 -7
  153. data/vendor/libgit2/include/git2/odb.h +156 -33
  154. data/vendor/libgit2/include/git2/odb_backend.h +132 -16
  155. data/vendor/libgit2/include/git2/oid.h +116 -17
  156. data/vendor/libgit2/include/git2/oidarray.h +7 -1
  157. data/vendor/libgit2/include/git2/pack.h +37 -9
  158. data/vendor/libgit2/include/git2/patch.h +10 -3
  159. data/vendor/libgit2/include/git2/pathspec.h +10 -1
  160. data/vendor/libgit2/include/git2/proxy.h +11 -1
  161. data/vendor/libgit2/include/git2/rebase.h +18 -7
  162. data/vendor/libgit2/include/git2/refdb.h +5 -2
  163. data/vendor/libgit2/include/git2/reflog.h +4 -3
  164. data/vendor/libgit2/include/git2/refs.h +11 -8
  165. data/vendor/libgit2/include/git2/refspec.h +14 -4
  166. data/vendor/libgit2/include/git2/remote.h +295 -54
  167. data/vendor/libgit2/include/git2/repository.h +95 -25
  168. data/vendor/libgit2/include/git2/reset.h +18 -5
  169. data/vendor/libgit2/include/git2/revert.h +9 -4
  170. data/vendor/libgit2/include/git2/revparse.h +4 -4
  171. data/vendor/libgit2/include/git2/revwalk.h +7 -3
  172. data/vendor/libgit2/include/git2/signature.h +47 -2
  173. data/vendor/libgit2/include/git2/stash.h +78 -10
  174. data/vendor/libgit2/include/git2/status.h +24 -11
  175. data/vendor/libgit2/include/git2/stdint.h +87 -85
  176. data/vendor/libgit2/include/git2/strarray.h +2 -16
  177. data/vendor/libgit2/include/git2/submodule.h +27 -11
  178. data/vendor/libgit2/include/git2/sys/alloc.h +12 -34
  179. data/vendor/libgit2/include/git2/sys/commit.h +77 -3
  180. data/vendor/libgit2/include/git2/sys/commit_graph.h +110 -59
  181. data/vendor/libgit2/include/git2/sys/config.h +80 -4
  182. data/vendor/libgit2/include/git2/sys/credential.h +4 -3
  183. data/vendor/libgit2/include/git2/sys/diff.h +21 -1
  184. data/vendor/libgit2/include/git2/sys/email.h +7 -0
  185. data/vendor/libgit2/include/git2/sys/errors.h +76 -0
  186. data/vendor/libgit2/include/git2/sys/filter.h +66 -3
  187. data/vendor/libgit2/include/git2/sys/hashsig.h +11 -0
  188. data/vendor/libgit2/include/git2/sys/index.h +3 -2
  189. data/vendor/libgit2/include/git2/sys/mempack.h +32 -2
  190. data/vendor/libgit2/include/git2/sys/merge.h +55 -7
  191. data/vendor/libgit2/include/git2/sys/midx.h +47 -4
  192. data/vendor/libgit2/include/git2/sys/odb_backend.h +10 -9
  193. data/vendor/libgit2/include/git2/sys/openssl.h +8 -1
  194. data/vendor/libgit2/include/git2/sys/path.h +12 -1
  195. data/vendor/libgit2/include/git2/sys/refdb_backend.h +40 -36
  196. data/vendor/libgit2/include/git2/sys/refs.h +3 -2
  197. data/vendor/libgit2/include/git2/sys/remote.h +53 -0
  198. data/vendor/libgit2/include/git2/sys/repository.h +63 -3
  199. data/vendor/libgit2/include/git2/sys/stream.h +26 -3
  200. data/vendor/libgit2/include/git2/sys/transport.h +87 -41
  201. data/vendor/libgit2/include/git2/tag.h +4 -1
  202. data/vendor/libgit2/include/git2/trace.h +9 -3
  203. data/vendor/libgit2/include/git2/transaction.h +3 -2
  204. data/vendor/libgit2/include/git2/transport.h +11 -3
  205. data/vendor/libgit2/include/git2/tree.h +20 -8
  206. data/vendor/libgit2/include/git2/types.h +26 -10
  207. data/vendor/libgit2/include/git2/version.h +63 -6
  208. data/vendor/libgit2/include/git2/worktree.h +30 -8
  209. data/vendor/libgit2/include/git2.h +1 -0
  210. data/vendor/libgit2/src/CMakeLists.txt +203 -420
  211. data/vendor/libgit2/src/README.md +12 -0
  212. data/vendor/libgit2/src/cli/CMakeLists.txt +56 -0
  213. data/vendor/libgit2/src/cli/README.md +26 -0
  214. data/vendor/libgit2/src/{branch.h → cli/cmd.c} +10 -8
  215. data/vendor/libgit2/src/cli/cmd.h +37 -0
  216. data/vendor/libgit2/src/cli/cmd_blame.c +287 -0
  217. data/vendor/libgit2/src/cli/cmd_cat_file.c +202 -0
  218. data/vendor/libgit2/src/cli/cmd_clone.c +190 -0
  219. data/vendor/libgit2/src/cli/cmd_config.c +241 -0
  220. data/vendor/libgit2/src/cli/cmd_hash_object.c +152 -0
  221. data/vendor/libgit2/src/cli/cmd_help.c +85 -0
  222. data/vendor/libgit2/src/cli/cmd_index_pack.c +114 -0
  223. data/vendor/libgit2/src/cli/cmd_init.c +102 -0
  224. data/vendor/libgit2/src/cli/common.c +168 -0
  225. data/vendor/libgit2/src/cli/common.h +63 -0
  226. data/vendor/libgit2/src/cli/error.h +51 -0
  227. data/vendor/libgit2/src/cli/main.c +134 -0
  228. data/vendor/libgit2/src/cli/opt.c +695 -0
  229. data/vendor/libgit2/src/cli/opt.h +367 -0
  230. data/vendor/libgit2/src/cli/opt_usage.c +263 -0
  231. data/vendor/libgit2/src/cli/opt_usage.h +40 -0
  232. data/vendor/libgit2/src/cli/progress.c +395 -0
  233. data/vendor/libgit2/src/cli/progress.h +129 -0
  234. data/vendor/libgit2/src/cli/sighandler.h +20 -0
  235. data/vendor/libgit2/src/cli/unix/sighandler.c +37 -0
  236. data/vendor/libgit2/src/cli/win32/precompiled.h +3 -0
  237. data/vendor/libgit2/src/cli/win32/sighandler.c +37 -0
  238. data/vendor/libgit2/src/libgit2/CMakeLists.txt +140 -0
  239. data/vendor/libgit2/src/{annotated_commit.c → libgit2/annotated_commit.c} +2 -2
  240. data/vendor/libgit2/src/{annotated_commit.h → libgit2/annotated_commit.h} +2 -2
  241. data/vendor/libgit2/src/{apply.c → libgit2/apply.c} +32 -34
  242. data/vendor/libgit2/src/{apply.h → libgit2/apply.h} +2 -2
  243. data/vendor/libgit2/src/{attr.c → libgit2/attr.c} +48 -31
  244. data/vendor/libgit2/src/{attr_file.c → libgit2/attr_file.c} +25 -20
  245. data/vendor/libgit2/src/{attr_file.h → libgit2/attr_file.h} +6 -4
  246. data/vendor/libgit2/src/{attrcache.c → libgit2/attrcache.c} +87 -46
  247. data/vendor/libgit2/src/{attrcache.h → libgit2/attrcache.h} +5 -9
  248. data/vendor/libgit2/src/{blame.c → libgit2/blame.c} +152 -57
  249. data/vendor/libgit2/src/{blame.h → libgit2/blame.h} +1 -0
  250. data/vendor/libgit2/src/{blame_git.c → libgit2/blame_git.c} +1 -2
  251. data/vendor/libgit2/src/{blob.c → libgit2/blob.c} +38 -29
  252. data/vendor/libgit2/src/{blob.h → libgit2/blob.h} +3 -3
  253. data/vendor/libgit2/src/{branch.c → libgit2/branch.c} +164 -118
  254. data/vendor/libgit2/src/libgit2/branch.h +31 -0
  255. data/vendor/libgit2/src/libgit2/buf.c +126 -0
  256. data/vendor/libgit2/src/libgit2/buf.h +50 -0
  257. data/vendor/libgit2/src/{cache.c → libgit2/cache.c} +22 -17
  258. data/vendor/libgit2/src/{cache.h → libgit2/cache.h} +7 -9
  259. data/vendor/libgit2/src/{checkout.c → libgit2/checkout.c} +107 -91
  260. data/vendor/libgit2/src/{checkout.h → libgit2/checkout.h} +0 -2
  261. data/vendor/libgit2/src/{cherrypick.c → libgit2/cherrypick.c} +14 -15
  262. data/vendor/libgit2/src/{clone.c → libgit2/clone.c} +254 -203
  263. data/vendor/libgit2/src/{clone.h → libgit2/clone.h} +4 -1
  264. data/vendor/libgit2/src/{commit.c → libgit2/commit.c} +296 -77
  265. data/vendor/libgit2/src/libgit2/commit.h +87 -0
  266. data/vendor/libgit2/src/{commit_graph.c → libgit2/commit_graph.c} +246 -135
  267. data/vendor/libgit2/src/{commit_graph.h → libgit2/commit_graph.h} +33 -8
  268. data/vendor/libgit2/src/{commit_list.c → libgit2/commit_list.c} +17 -7
  269. data/vendor/libgit2/src/{commit_list.h → libgit2/commit_list.h} +1 -0
  270. data/vendor/libgit2/src/libgit2/common.h +55 -0
  271. data/vendor/libgit2/src/{config.c → libgit2/config.c} +490 -360
  272. data/vendor/libgit2/src/libgit2/config.cmake.in +3 -0
  273. data/vendor/libgit2/src/{config.h → libgit2/config.h} +24 -6
  274. data/vendor/libgit2/src/{config_backend.h → libgit2/config_backend.h} +8 -10
  275. data/vendor/libgit2/src/{config_cache.c → libgit2/config_cache.c} +4 -5
  276. data/vendor/libgit2/src/{config_file.c → libgit2/config_file.c} +212 -183
  277. data/vendor/libgit2/src/libgit2/config_list.c +285 -0
  278. data/vendor/libgit2/src/libgit2/config_list.h +32 -0
  279. data/vendor/libgit2/src/libgit2/config_mem.c +374 -0
  280. data/vendor/libgit2/src/{config_parse.c → libgit2/config_parse.c} +37 -32
  281. data/vendor/libgit2/src/{config_snapshot.c → libgit2/config_snapshot.c} +24 -31
  282. data/vendor/libgit2/src/{crlf.c → libgit2/crlf.c} +24 -21
  283. data/vendor/libgit2/src/{describe.c → libgit2/describe.c} +62 -51
  284. data/vendor/libgit2/src/{diff.c → libgit2/diff.c} +44 -14
  285. data/vendor/libgit2/src/{diff.h → libgit2/diff.h} +8 -10
  286. data/vendor/libgit2/src/{diff_driver.c → libgit2/diff_driver.c} +46 -55
  287. data/vendor/libgit2/src/{diff_driver.h → libgit2/diff_driver.h} +5 -5
  288. data/vendor/libgit2/src/{diff_file.c → libgit2/diff_file.c} +45 -27
  289. data/vendor/libgit2/src/{diff_generate.c → libgit2/diff_generate.c} +70 -20
  290. data/vendor/libgit2/src/{diff_generate.h → libgit2/diff_generate.h} +5 -3
  291. data/vendor/libgit2/src/{diff_parse.c → libgit2/diff_parse.c} +22 -6
  292. data/vendor/libgit2/src/{diff_print.c → libgit2/diff_print.c} +192 -105
  293. data/vendor/libgit2/src/{diff_stats.c → libgit2/diff_stats.c} +40 -29
  294. data/vendor/libgit2/src/libgit2/diff_stats.h +18 -0
  295. data/vendor/libgit2/src/{diff_tform.c → libgit2/diff_tform.c} +49 -16
  296. data/vendor/libgit2/src/{diff_xdiff.c → libgit2/diff_xdiff.c} +4 -8
  297. data/vendor/libgit2/src/{diff_xdiff.h → libgit2/diff_xdiff.h} +1 -1
  298. data/vendor/libgit2/src/{email.c → libgit2/email.c} +58 -40
  299. data/vendor/libgit2/src/{email.h → libgit2/email.h} +1 -1
  300. data/vendor/libgit2/src/{transports/ssh.h → libgit2/experimental.h.in} +3 -4
  301. data/vendor/libgit2/src/{fetch.c → libgit2/fetch.c} +105 -30
  302. data/vendor/libgit2/src/{fetch.h → libgit2/fetch.h} +1 -3
  303. data/vendor/libgit2/src/{fetchhead.c → libgit2/fetchhead.c} +30 -28
  304. data/vendor/libgit2/src/{filter.c → libgit2/filter.c} +132 -58
  305. data/vendor/libgit2/src/{filter.h → libgit2/filter.h} +26 -5
  306. data/vendor/libgit2/src/{win32 → libgit2}/git2.rc +3 -3
  307. data/vendor/libgit2/src/libgit2/grafts.c +270 -0
  308. data/vendor/libgit2/src/libgit2/grafts.h +35 -0
  309. data/vendor/libgit2/src/{graph.c → libgit2/graph.c} +1 -1
  310. data/vendor/libgit2/src/libgit2/hashmap_oid.h +30 -0
  311. data/vendor/libgit2/src/{ident.c → libgit2/ident.c} +20 -20
  312. data/vendor/libgit2/src/{ignore.c → libgit2/ignore.c} +44 -39
  313. data/vendor/libgit2/src/{ignore.h → libgit2/ignore.h} +2 -2
  314. data/vendor/libgit2/src/{index.c → libgit2/index.c} +460 -276
  315. data/vendor/libgit2/src/{index.h → libgit2/index.h} +21 -5
  316. data/vendor/libgit2/src/libgit2/index_map.c +95 -0
  317. data/vendor/libgit2/src/libgit2/index_map.h +28 -0
  318. data/vendor/libgit2/src/{indexer.c → libgit2/indexer.c} +208 -124
  319. data/vendor/libgit2/src/{iterator.c → libgit2/iterator.c} +102 -71
  320. data/vendor/libgit2/src/{iterator.h → libgit2/iterator.h} +8 -5
  321. data/vendor/libgit2/src/libgit2/libgit2.c +268 -0
  322. data/vendor/libgit2/src/{mailmap.c → libgit2/mailmap.c} +39 -37
  323. data/vendor/libgit2/src/{merge.c → libgit2/merge.c} +83 -73
  324. data/vendor/libgit2/src/{merge.h → libgit2/merge.h} +1 -14
  325. data/vendor/libgit2/src/{merge_driver.c → libgit2/merge_driver.c} +4 -4
  326. data/vendor/libgit2/src/{merge_file.c → libgit2/merge_file.c} +13 -5
  327. data/vendor/libgit2/src/{message.c → libgit2/message.c} +21 -10
  328. data/vendor/libgit2/src/{midx.c → libgit2/midx.c} +174 -112
  329. data/vendor/libgit2/src/{midx.h → libgit2/midx.h} +17 -6
  330. data/vendor/libgit2/src/{mwindow.c → libgit2/mwindow.c} +53 -57
  331. data/vendor/libgit2/src/{mwindow.h → libgit2/mwindow.h} +9 -2
  332. data/vendor/libgit2/src/{notes.c → libgit2/notes.c} +29 -37
  333. data/vendor/libgit2/src/{object.c → libgit2/object.c} +166 -35
  334. data/vendor/libgit2/src/{object.h → libgit2/object.h} +17 -2
  335. data/vendor/libgit2/src/{odb.c → libgit2/odb.c} +261 -88
  336. data/vendor/libgit2/src/{odb.h → libgit2/odb.h} +44 -5
  337. data/vendor/libgit2/src/{odb_loose.c → libgit2/odb_loose.c} +192 -134
  338. data/vendor/libgit2/src/{odb_mempack.c → libgit2/odb_mempack.c} +67 -22
  339. data/vendor/libgit2/src/{odb_pack.c → libgit2/odb_pack.c} +162 -89
  340. data/vendor/libgit2/src/{oid.c → libgit2/oid.c} +171 -92
  341. data/vendor/libgit2/src/libgit2/oid.h +284 -0
  342. data/vendor/libgit2/src/libgit2/oidarray.c +89 -0
  343. data/vendor/libgit2/src/{oidarray.h → libgit2/oidarray.h} +5 -1
  344. data/vendor/libgit2/src/{pack-objects.c → libgit2/pack-objects.c} +126 -66
  345. data/vendor/libgit2/src/{pack-objects.h → libgit2/pack-objects.h} +28 -12
  346. data/vendor/libgit2/src/{pack.c → libgit2/pack.c} +146 -111
  347. data/vendor/libgit2/src/{pack.h → libgit2/pack.h} +45 -25
  348. data/vendor/libgit2/src/{parse.c → libgit2/parse.c} +8 -4
  349. data/vendor/libgit2/src/{parse.h → libgit2/parse.h} +1 -1
  350. data/vendor/libgit2/src/{patch.c → libgit2/patch.c} +3 -3
  351. data/vendor/libgit2/src/{patch.h → libgit2/patch.h} +8 -1
  352. data/vendor/libgit2/src/{patch_generate.c → libgit2/patch_generate.c} +51 -16
  353. data/vendor/libgit2/src/{patch_generate.h → libgit2/patch_generate.h} +5 -5
  354. data/vendor/libgit2/src/{patch_parse.c → libgit2/patch_parse.c} +42 -34
  355. data/vendor/libgit2/src/libgit2/path.c +375 -0
  356. data/vendor/libgit2/src/libgit2/path.h +68 -0
  357. data/vendor/libgit2/src/{pathspec.c → libgit2/pathspec.c} +7 -7
  358. data/vendor/libgit2/src/{pathspec.h → libgit2/pathspec.h} +2 -2
  359. data/vendor/libgit2/src/{proxy.c → libgit2/proxy.c} +4 -1
  360. data/vendor/libgit2/src/{proxy.h → libgit2/proxy.h} +1 -1
  361. data/vendor/libgit2/src/{push.c → libgit2/push.c} +116 -60
  362. data/vendor/libgit2/src/{push.h → libgit2/push.h} +5 -16
  363. data/vendor/libgit2/src/{reader.c → libgit2/reader.c} +9 -9
  364. data/vendor/libgit2/src/{reader.h → libgit2/reader.h} +2 -2
  365. data/vendor/libgit2/src/{rebase.c → libgit2/rebase.c} +147 -147
  366. data/vendor/libgit2/src/{refdb_fs.c → libgit2/refdb_fs.c} +639 -254
  367. data/vendor/libgit2/src/{reflog.c → libgit2/reflog.c} +8 -7
  368. data/vendor/libgit2/src/{reflog.h → libgit2/reflog.h} +3 -2
  369. data/vendor/libgit2/src/{refs.c → libgit2/refs.c} +67 -39
  370. data/vendor/libgit2/src/{refs.h → libgit2/refs.h} +8 -3
  371. data/vendor/libgit2/src/{refspec.c → libgit2/refspec.c} +60 -38
  372. data/vendor/libgit2/src/{refspec.h → libgit2/refspec.h} +13 -2
  373. data/vendor/libgit2/src/{remote.c → libgit2/remote.c} +821 -454
  374. data/vendor/libgit2/src/libgit2/remote.h +101 -0
  375. data/vendor/libgit2/src/{repository.c → libgit2/repository.c} +1377 -594
  376. data/vendor/libgit2/src/{repository.h → libgit2/repository.h} +43 -12
  377. data/vendor/libgit2/src/{reset.c → libgit2/reset.c} +8 -5
  378. data/vendor/libgit2/src/{revert.c → libgit2/revert.c} +18 -22
  379. data/vendor/libgit2/src/{revparse.c → libgit2/revparse.c} +76 -44
  380. data/vendor/libgit2/src/{revwalk.c → libgit2/revwalk.c} +48 -19
  381. data/vendor/libgit2/src/{revwalk.h → libgit2/revwalk.h} +3 -3
  382. data/vendor/libgit2/src/{libgit2.c → libgit2/settings.c} +162 -95
  383. data/vendor/libgit2/src/{settings.h → libgit2/settings.h} +6 -2
  384. data/vendor/libgit2/src/{signature.c → libgit2/signature.c} +144 -21
  385. data/vendor/libgit2/src/{signature.h → libgit2/signature.h} +1 -2
  386. data/vendor/libgit2/src/{stash.c → libgit2/stash.c} +243 -68
  387. data/vendor/libgit2/src/{status.c → libgit2/status.c} +5 -2
  388. data/vendor/libgit2/src/{strarray.c → libgit2/strarray.c} +1 -0
  389. data/vendor/libgit2/src/libgit2/strarray.h +25 -0
  390. data/vendor/libgit2/src/{streams → libgit2/streams}/mbedtls.c +62 -67
  391. data/vendor/libgit2/src/{streams → libgit2/streams}/openssl.c +41 -24
  392. data/vendor/libgit2/src/{streams → libgit2/streams}/openssl.h +2 -0
  393. data/vendor/libgit2/src/{streams → libgit2/streams}/openssl_dynamic.c +11 -3
  394. data/vendor/libgit2/src/{streams → libgit2/streams}/openssl_dynamic.h +6 -3
  395. data/vendor/libgit2/src/libgit2/streams/schannel.c +715 -0
  396. data/vendor/libgit2/src/libgit2/streams/schannel.h +28 -0
  397. data/vendor/libgit2/src/libgit2/streams/socket.c +428 -0
  398. data/vendor/libgit2/src/{streams → libgit2/streams}/socket.h +3 -1
  399. data/vendor/libgit2/src/{streams → libgit2/streams}/stransport.c +79 -19
  400. data/vendor/libgit2/src/{streams → libgit2/streams}/tls.c +5 -0
  401. data/vendor/libgit2/src/{submodule.c → libgit2/submodule.c} +279 -220
  402. data/vendor/libgit2/src/{submodule.h → libgit2/submodule.h} +10 -11
  403. data/vendor/libgit2/src/libgit2/sysdir.c +650 -0
  404. data/vendor/libgit2/src/{sysdir.h → libgit2/sysdir.h} +55 -18
  405. data/vendor/libgit2/src/{tag.c → libgit2/tag.c} +74 -43
  406. data/vendor/libgit2/src/{tag.h → libgit2/tag.h} +2 -2
  407. data/vendor/libgit2/src/{trace.c → libgit2/trace.c} +1 -14
  408. data/vendor/libgit2/src/{trace.h → libgit2/trace.h} +5 -22
  409. data/vendor/libgit2/src/{trailer.c → libgit2/trailer.c} +7 -7
  410. data/vendor/libgit2/src/{transaction.c → libgit2/transaction.c} +27 -21
  411. data/vendor/libgit2/src/{transaction.h → libgit2/transaction.h} +4 -1
  412. data/vendor/libgit2/src/{transport.c → libgit2/transport.c} +14 -11
  413. data/vendor/libgit2/src/{transports → libgit2/transports}/auth.c +7 -9
  414. data/vendor/libgit2/src/{transports → libgit2/transports}/auth.h +3 -5
  415. data/vendor/libgit2/src/{transports/auth_negotiate.c → libgit2/transports/auth_gssapi.c} +44 -45
  416. data/vendor/libgit2/src/{transports → libgit2/transports}/auth_negotiate.h +1 -1
  417. data/vendor/libgit2/src/{transports → libgit2/transports}/auth_ntlm.h +1 -2
  418. data/vendor/libgit2/src/{transports/auth_ntlm.c → libgit2/transports/auth_ntlmclient.c} +22 -22
  419. data/vendor/libgit2/src/libgit2/transports/auth_sspi.c +341 -0
  420. data/vendor/libgit2/src/{transports → libgit2/transports}/credential.c +1 -1
  421. data/vendor/libgit2/src/{transports → libgit2/transports}/git.c +16 -19
  422. data/vendor/libgit2/src/{transports → libgit2/transports}/http.c +49 -24
  423. data/vendor/libgit2/src/{transports → libgit2/transports}/http.h +0 -11
  424. data/vendor/libgit2/src/{transports → libgit2/transports}/httpclient.c +188 -134
  425. data/vendor/libgit2/src/{transports → libgit2/transports}/httpclient.h +10 -0
  426. data/vendor/libgit2/src/libgit2/transports/httpparser.c +128 -0
  427. data/vendor/libgit2/src/libgit2/transports/httpparser.h +99 -0
  428. data/vendor/libgit2/src/{transports → libgit2/transports}/local.c +159 -127
  429. data/vendor/libgit2/src/{transports → libgit2/transports}/smart.c +142 -165
  430. data/vendor/libgit2/src/{transports → libgit2/transports}/smart.h +56 -36
  431. data/vendor/libgit2/src/{transports → libgit2/transports}/smart_pkt.c +307 -74
  432. data/vendor/libgit2/src/{transports → libgit2/transports}/smart_protocol.c +297 -97
  433. data/vendor/libgit2/src/libgit2/transports/ssh.c +85 -0
  434. data/vendor/libgit2/src/libgit2/transports/ssh_exec.c +347 -0
  435. data/vendor/libgit2/src/libgit2/transports/ssh_exec.h +26 -0
  436. data/vendor/libgit2/src/{transports/ssh.c → libgit2/transports/ssh_libssh2.c} +414 -268
  437. data/vendor/libgit2/src/libgit2/transports/ssh_libssh2.h +28 -0
  438. data/vendor/libgit2/src/{transports → libgit2/transports}/winhttp.c +101 -75
  439. data/vendor/libgit2/src/{tree-cache.c → libgit2/tree-cache.c} +30 -20
  440. data/vendor/libgit2/src/{tree-cache.h → libgit2/tree-cache.h} +7 -5
  441. data/vendor/libgit2/src/{tree.c → libgit2/tree.c} +128 -110
  442. data/vendor/libgit2/src/{tree.h → libgit2/tree.h} +7 -6
  443. data/vendor/libgit2/src/{worktree.c → libgit2/worktree.c} +160 -121
  444. data/vendor/libgit2/src/{worktree.h → libgit2/worktree.h} +1 -1
  445. data/vendor/libgit2/src/util/CMakeLists.txt +77 -0
  446. data/vendor/libgit2/src/{alloc.c → util/alloc.c} +69 -7
  447. data/vendor/libgit2/src/util/alloc.h +65 -0
  448. data/vendor/libgit2/src/util/allocators/debugalloc.c +73 -0
  449. data/vendor/libgit2/src/util/allocators/debugalloc.h +17 -0
  450. data/vendor/libgit2/src/util/allocators/failalloc.c +32 -0
  451. data/vendor/libgit2/src/util/allocators/failalloc.h +17 -0
  452. data/vendor/libgit2/src/util/allocators/stdalloc.c +37 -0
  453. data/vendor/libgit2/src/{allocators → util/allocators}/stdalloc.h +1 -1
  454. data/vendor/libgit2/src/util/allocators/win32_leakcheck.c +50 -0
  455. data/vendor/libgit2/src/{allocators → util/allocators}/win32_leakcheck.h +1 -1
  456. data/vendor/libgit2/src/{array.h → util/array.h} +25 -19
  457. data/vendor/libgit2/src/{assert_safe.h → util/assert_safe.h} +16 -0
  458. data/vendor/libgit2/src/{cc-compat.h → util/cc-compat.h} +5 -1
  459. data/vendor/libgit2/src/util/ctype_compat.h +70 -0
  460. data/vendor/libgit2/src/{date.c → util/date.c} +35 -33
  461. data/vendor/libgit2/src/util/date.h +45 -0
  462. data/vendor/libgit2/src/util/errors.c +401 -0
  463. data/vendor/libgit2/src/{errors.h → util/errors.h} +22 -19
  464. data/vendor/libgit2/src/{filebuf.c → util/filebuf.c} +35 -30
  465. data/vendor/libgit2/src/{filebuf.h → util/filebuf.h} +21 -8
  466. data/vendor/libgit2/src/{path.c → util/fs_path.c} +591 -615
  467. data/vendor/libgit2/src/{path.h → util/fs_path.h} +257 -181
  468. data/vendor/libgit2/src/{futils.c → util/futils.c} +144 -95
  469. data/vendor/libgit2/src/{futils.h → util/futils.h} +40 -18
  470. data/vendor/libgit2/src/{features.h.in → util/git2_features.h.in} +33 -2
  471. data/vendor/libgit2/src/{common.h → util/git2_util.h} +26 -59
  472. data/vendor/libgit2/src/util/hash/builtin.c +53 -0
  473. data/vendor/libgit2/src/{hash/sha1/openssl.h → util/hash/builtin.h} +6 -6
  474. data/vendor/libgit2/src/{hash/sha1 → util/hash}/collisiondetect.c +3 -3
  475. data/vendor/libgit2/src/{hash/sha1 → util/hash}/collisiondetect.h +3 -3
  476. data/vendor/libgit2/src/util/hash/common_crypto.c +112 -0
  477. data/vendor/libgit2/src/{hash/sha1 → util/hash}/common_crypto.h +11 -3
  478. data/vendor/libgit2/src/util/hash/mbedtls.c +92 -0
  479. data/vendor/libgit2/src/{hash/sha1 → util/hash}/mbedtls.h +14 -4
  480. data/vendor/libgit2/src/util/hash/openssl.c +347 -0
  481. data/vendor/libgit2/src/util/hash/openssl.h +61 -0
  482. data/vendor/libgit2/src/util/hash/rfc6234/sha.h +243 -0
  483. data/vendor/libgit2/src/util/hash/rfc6234/sha224-256.c +601 -0
  484. data/vendor/libgit2/src/util/hash/sha.h +73 -0
  485. data/vendor/libgit2/src/{hash/sha1 → util/hash}/sha1dc/sha1.c +1 -1
  486. data/vendor/libgit2/src/util/hash/win32.c +549 -0
  487. data/vendor/libgit2/src/util/hash/win32.h +60 -0
  488. data/vendor/libgit2/src/util/hash.c +158 -0
  489. data/vendor/libgit2/src/util/hash.h +61 -0
  490. data/vendor/libgit2/src/util/hashmap.h +424 -0
  491. data/vendor/libgit2/src/util/hashmap_str.h +43 -0
  492. data/vendor/libgit2/src/{integer.h → util/integer.h} +3 -1
  493. data/vendor/libgit2/src/{map.h → util/map.h} +1 -1
  494. data/vendor/libgit2/src/util/net.c +1160 -0
  495. data/vendor/libgit2/src/{net.h → util/net.h} +45 -4
  496. data/vendor/libgit2/src/{pool.c → util/pool.c} +1 -1
  497. data/vendor/libgit2/src/{pool.h → util/pool.h} +6 -1
  498. data/vendor/libgit2/src/{posix.c → util/posix.c} +57 -3
  499. data/vendor/libgit2/src/{posix.h → util/posix.h} +26 -1
  500. data/vendor/libgit2/src/{pqueue.h → util/pqueue.h} +3 -3
  501. data/vendor/libgit2/src/util/process.h +222 -0
  502. data/vendor/libgit2/src/util/rand.c +230 -0
  503. data/vendor/libgit2/src/util/rand.h +37 -0
  504. data/vendor/libgit2/src/{regexp.c → util/regexp.c} +5 -5
  505. data/vendor/libgit2/src/{regexp.h → util/regexp.h} +1 -1
  506. data/vendor/libgit2/src/{runtime.c → util/runtime.c} +1 -1
  507. data/vendor/libgit2/src/{runtime.h → util/runtime.h} +1 -1
  508. data/vendor/libgit2/src/{sortedcache.c → util/sortedcache.c} +15 -14
  509. data/vendor/libgit2/src/{sortedcache.h → util/sortedcache.h} +5 -5
  510. data/vendor/libgit2/src/util/staticstr.h +66 -0
  511. data/vendor/libgit2/src/{buffer.c → util/str.c} +159 -153
  512. data/vendor/libgit2/src/util/str.h +357 -0
  513. data/vendor/libgit2/src/util/strlist.c +108 -0
  514. data/vendor/libgit2/src/util/strlist.h +36 -0
  515. data/vendor/libgit2/src/{thread.c → util/thread.c} +1 -1
  516. data/vendor/libgit2/src/{thread.h → util/thread.h} +23 -22
  517. data/vendor/libgit2/src/{tsort.c → util/tsort.c} +1 -1
  518. data/vendor/libgit2/src/{unix → util/unix}/map.c +1 -3
  519. data/vendor/libgit2/src/{unix → util/unix}/posix.h +1 -6
  520. data/vendor/libgit2/src/util/unix/process.c +629 -0
  521. data/vendor/libgit2/src/{unix → util/unix}/realpath.c +24 -8
  522. data/vendor/libgit2/src/{utf8.c → util/utf8.c} +1 -1
  523. data/vendor/libgit2/src/{utf8.h → util/utf8.h} +1 -1
  524. data/vendor/libgit2/src/{util.c → util/util.c} +24 -19
  525. data/vendor/libgit2/src/{util.h → util/util.h} +30 -81
  526. data/vendor/libgit2/src/{varint.h → util/varint.h} +1 -1
  527. data/vendor/libgit2/src/{vector.c → util/vector.c} +3 -3
  528. data/vendor/libgit2/src/{vector.h → util/vector.h} +4 -4
  529. data/vendor/libgit2/src/{wildmatch.h → util/wildmatch.h} +1 -1
  530. data/vendor/libgit2/src/{win32 → util/win32}/dir.h +1 -1
  531. data/vendor/libgit2/src/{win32 → util/win32}/error.c +1 -1
  532. data/vendor/libgit2/src/{win32 → util/win32}/error.h +1 -1
  533. data/vendor/libgit2/src/{win32 → util/win32}/map.c +1 -1
  534. data/vendor/libgit2/src/{win32 → util/win32}/path_w32.c +148 -17
  535. data/vendor/libgit2/src/{win32 → util/win32}/path_w32.h +3 -1
  536. data/vendor/libgit2/src/{win32 → util/win32}/posix.h +1 -2
  537. data/vendor/libgit2/src/{win32 → util/win32}/posix_w32.c +42 -35
  538. data/vendor/libgit2/src/util/win32/precompiled.c +1 -0
  539. data/vendor/libgit2/src/{win32 → util/win32}/precompiled.h +1 -1
  540. data/vendor/libgit2/src/util/win32/process.c +506 -0
  541. data/vendor/libgit2/src/{win32 → util/win32}/thread.h +1 -1
  542. data/vendor/libgit2/src/util/win32/utf-conv.c +144 -0
  543. data/vendor/libgit2/src/util/win32/utf-conv.h +127 -0
  544. data/vendor/libgit2/src/{win32 → util/win32}/w32_buffer.c +2 -3
  545. data/vendor/libgit2/src/{win32 → util/win32}/w32_buffer.h +3 -4
  546. data/vendor/libgit2/src/{win32 → util/win32}/w32_leakcheck.c +1 -1
  547. data/vendor/libgit2/src/{win32 → util/win32}/w32_leakcheck.h +1 -1
  548. data/vendor/libgit2/src/{win32 → util/win32}/w32_util.c +1 -1
  549. data/vendor/libgit2/src/{win32 → util/win32}/w32_util.h +1 -1
  550. data/vendor/libgit2/src/{zstream.c → util/zstream.c} +5 -5
  551. data/vendor/libgit2/src/{zstream.h → util/zstream.h} +5 -5
  552. metadata +431 -362
  553. data/vendor/libgit2/cmake/FindIconv.cmake +0 -45
  554. data/vendor/libgit2/deps/http-parser/CMakeLists.txt +0 -6
  555. data/vendor/libgit2/deps/http-parser/COPYING +0 -23
  556. data/vendor/libgit2/deps/http-parser/http_parser.c +0 -2182
  557. data/vendor/libgit2/deps/http-parser/http_parser.h +0 -305
  558. data/vendor/libgit2/deps/zlib/COPYING +0 -27
  559. data/vendor/libgit2/include/git2/sys/reflog.h +0 -21
  560. data/vendor/libgit2/src/alloc.h +0 -40
  561. data/vendor/libgit2/src/allocators/failalloc.c +0 -92
  562. data/vendor/libgit2/src/allocators/failalloc.h +0 -23
  563. data/vendor/libgit2/src/allocators/stdalloc.c +0 -150
  564. data/vendor/libgit2/src/allocators/win32_leakcheck.c +0 -118
  565. data/vendor/libgit2/src/buffer.h +0 -374
  566. data/vendor/libgit2/src/commit.h +0 -46
  567. data/vendor/libgit2/src/config_entries.c +0 -237
  568. data/vendor/libgit2/src/config_entries.h +0 -24
  569. data/vendor/libgit2/src/config_mem.c +0 -220
  570. data/vendor/libgit2/src/errors.c +0 -238
  571. data/vendor/libgit2/src/hash/sha1/common_crypto.c +0 -57
  572. data/vendor/libgit2/src/hash/sha1/generic.c +0 -300
  573. data/vendor/libgit2/src/hash/sha1/generic.h +0 -19
  574. data/vendor/libgit2/src/hash/sha1/mbedtls.c +0 -46
  575. data/vendor/libgit2/src/hash/sha1/openssl.c +0 -59
  576. data/vendor/libgit2/src/hash/sha1/win32.c +0 -333
  577. data/vendor/libgit2/src/hash/sha1/win32.h +0 -128
  578. data/vendor/libgit2/src/hash/sha1.h +0 -38
  579. data/vendor/libgit2/src/hash.c +0 -110
  580. data/vendor/libgit2/src/hash.h +0 -46
  581. data/vendor/libgit2/src/idxmap.c +0 -157
  582. data/vendor/libgit2/src/idxmap.h +0 -177
  583. data/vendor/libgit2/src/khash.h +0 -615
  584. data/vendor/libgit2/src/libgit2.h +0 -15
  585. data/vendor/libgit2/src/message.h +0 -17
  586. data/vendor/libgit2/src/net.c +0 -540
  587. data/vendor/libgit2/src/netops.c +0 -125
  588. data/vendor/libgit2/src/netops.h +0 -68
  589. data/vendor/libgit2/src/offmap.c +0 -101
  590. data/vendor/libgit2/src/offmap.h +0 -133
  591. data/vendor/libgit2/src/oid.h +0 -51
  592. data/vendor/libgit2/src/oidarray.c +0 -43
  593. data/vendor/libgit2/src/oidmap.c +0 -107
  594. data/vendor/libgit2/src/oidmap.h +0 -128
  595. data/vendor/libgit2/src/remote.h +0 -55
  596. data/vendor/libgit2/src/streams/socket.c +0 -239
  597. data/vendor/libgit2/src/strmap.c +0 -100
  598. data/vendor/libgit2/src/strmap.h +0 -131
  599. data/vendor/libgit2/src/sysdir.c +0 -347
  600. data/vendor/libgit2/src/threadstate.c +0 -84
  601. data/vendor/libgit2/src/threadstate.h +0 -24
  602. data/vendor/libgit2/src/win32/findfile.c +0 -230
  603. data/vendor/libgit2/src/win32/findfile.h +0 -19
  604. data/vendor/libgit2/src/win32/utf-conv.c +0 -146
  605. data/vendor/libgit2/src/win32/utf-conv.h +0 -60
  606. /data/vendor/libgit2/{src → deps}/xdiff/xemit.h +0 -0
  607. /data/vendor/libgit2/{src → deps}/xdiff/xprepare.h +0 -0
  608. /data/vendor/libgit2/{src → deps}/xdiff/xtypes.h +0 -0
  609. /data/vendor/libgit2/src/{win32 → cli/win32}/precompiled.c +0 -0
  610. /data/vendor/libgit2/src/{attr.h → libgit2/attr.h} +0 -0
  611. /data/vendor/libgit2/src/{blame_git.h → libgit2/blame_git.h} +0 -0
  612. /data/vendor/libgit2/src/{config_parse.h → libgit2/config_parse.h} +0 -0
  613. /data/vendor/libgit2/src/{delta.c → libgit2/delta.c} +0 -0
  614. /data/vendor/libgit2/src/{delta.h → libgit2/delta.h} +0 -0
  615. /data/vendor/libgit2/src/{diff_file.h → libgit2/diff_file.h} +0 -0
  616. /data/vendor/libgit2/src/{diff_parse.h → libgit2/diff_parse.h} +0 -0
  617. /data/vendor/libgit2/src/{diff_tform.h → libgit2/diff_tform.h} +0 -0
  618. /data/vendor/libgit2/src/{fetchhead.h → libgit2/fetchhead.h} +0 -0
  619. /data/vendor/libgit2/src/{hashsig.c → libgit2/hashsig.c} +0 -0
  620. /data/vendor/libgit2/src/{indexer.h → libgit2/indexer.h} +0 -0
  621. /data/vendor/libgit2/src/{mailmap.h → libgit2/mailmap.h} +0 -0
  622. /data/vendor/libgit2/src/{merge_driver.h → libgit2/merge_driver.h} +0 -0
  623. /data/vendor/libgit2/src/{notes.h → libgit2/notes.h} +0 -0
  624. /data/vendor/libgit2/src/{object_api.c → libgit2/object_api.c} +0 -0
  625. /data/vendor/libgit2/src/{patch_parse.h → libgit2/patch_parse.h} +0 -0
  626. /data/vendor/libgit2/src/{refdb.c → libgit2/refdb.c} +0 -0
  627. /data/vendor/libgit2/src/{refdb.h → libgit2/refdb.h} +0 -0
  628. /data/vendor/libgit2/src/{repo_template.h → libgit2/repo_template.h} +0 -0
  629. /data/vendor/libgit2/src/{status.h → libgit2/status.h} +0 -0
  630. /data/vendor/libgit2/src/{stream.h → libgit2/stream.h} +0 -0
  631. /data/vendor/libgit2/src/{streams → libgit2/streams}/mbedtls.h +0 -0
  632. /data/vendor/libgit2/src/{streams → libgit2/streams}/openssl_legacy.c +0 -0
  633. /data/vendor/libgit2/src/{streams → libgit2/streams}/openssl_legacy.h +0 -0
  634. /data/vendor/libgit2/src/{streams → libgit2/streams}/registry.c +0 -0
  635. /data/vendor/libgit2/src/{streams → libgit2/streams}/registry.h +0 -0
  636. /data/vendor/libgit2/src/{streams → libgit2/streams}/stransport.h +0 -0
  637. /data/vendor/libgit2/src/{streams → libgit2/streams}/tls.h +0 -0
  638. /data/vendor/libgit2/src/{transports → libgit2/transports}/credential_helpers.c +0 -0
  639. /data/vendor/libgit2/src/{userdiff.h → libgit2/userdiff.h} +0 -0
  640. /data/vendor/libgit2/src/{bitvec.h → util/bitvec.h} +0 -0
  641. /data/vendor/libgit2/src/{hash/sha1 → util/hash}/sha1dc/sha1.h +0 -0
  642. /data/vendor/libgit2/src/{hash/sha1 → util/hash}/sha1dc/ubc_check.c +0 -0
  643. /data/vendor/libgit2/src/{hash/sha1 → util/hash}/sha1dc/ubc_check.h +0 -0
  644. /data/vendor/libgit2/src/{pqueue.c → util/pqueue.c} +0 -0
  645. /data/vendor/libgit2/src/{strnlen.h → util/strnlen.h} +0 -0
  646. /data/vendor/libgit2/src/{unix → util/unix}/pthread.h +0 -0
  647. /data/vendor/libgit2/src/{varint.c → util/varint.c} +0 -0
  648. /data/vendor/libgit2/src/{wildmatch.c → util/wildmatch.c} +0 -0
  649. /data/vendor/libgit2/src/{win32 → util/win32}/dir.c +0 -0
  650. /data/vendor/libgit2/src/{win32 → util/win32}/mingw-compat.h +0 -0
  651. /data/vendor/libgit2/src/{win32 → util/win32}/msvc-compat.h +0 -0
  652. /data/vendor/libgit2/src/{win32 → util/win32}/reparse.h +0 -0
  653. /data/vendor/libgit2/src/{win32 → util/win32}/thread.c +0 -0
  654. /data/vendor/libgit2/src/{win32 → util/win32}/version.h +0 -0
  655. /data/vendor/libgit2/src/{win32 → util/win32}/w32_common.h +0 -0
  656. /data/vendor/libgit2/src/{win32 → util/win32}/win32-compat.h +0 -0
@@ -7,11 +7,8 @@
7
7
 
8
8
  #include "remote.h"
9
9
 
10
- #include "git2/config.h"
11
- #include "git2/types.h"
12
- #include "git2/oid.h"
13
- #include "git2/net.h"
14
-
10
+ #include "buf.h"
11
+ #include "branch.h"
15
12
  #include "config.h"
16
13
  #include "repository.h"
17
14
  #include "fetch.h"
@@ -19,6 +16,14 @@
19
16
  #include "refspec.h"
20
17
  #include "fetchhead.h"
21
18
  #include "push.h"
19
+ #include "proxy.h"
20
+ #include "strarray.h"
21
+
22
+ #include "git2/config.h"
23
+ #include "git2/types.h"
24
+ #include "git2/oid.h"
25
+ #include "git2/net.h"
26
+ #include "transports/smart.h"
22
27
 
23
28
  #define CONFIG_URL_FMT "remote.%s.url"
24
29
  #define CONFIG_PUSHURL_FMT "remote.%s.pushurl"
@@ -28,7 +33,7 @@
28
33
 
29
34
  static int dwim_refspecs(git_vector *out, git_vector *refspecs, git_vector *refs);
30
35
  static int lookup_remote_prune_config(git_remote *remote, git_config *config, const char *name);
31
- char *apply_insteadof(git_config *config, const char *url, int direction);
36
+ static int apply_insteadof(char **out, git_config *config, const char *url, int direction, bool use_default_if_empty);
32
37
 
33
38
  static int add_refspec_to(git_vector *vector, const char *string, bool is_fetch)
34
39
  {
@@ -60,14 +65,14 @@ static int add_refspec(git_remote *remote, const char *string, bool is_fetch)
60
65
  static int download_tags_value(git_remote *remote, git_config *cfg)
61
66
  {
62
67
  git_config_entry *ce;
63
- git_buf buf = GIT_BUF_INIT;
68
+ git_str buf = GIT_STR_INIT;
64
69
  int error;
65
70
 
66
- if (git_buf_printf(&buf, "remote.%s.tagopt", remote->name) < 0)
71
+ if (git_str_printf(&buf, "remote.%s.tagopt", remote->name) < 0)
67
72
  return -1;
68
73
 
69
- error = git_config__lookup_entry(&ce, cfg, git_buf_cstr(&buf), false);
70
- git_buf_dispose(&buf);
74
+ error = git_config__lookup_entry(&ce, cfg, git_str_cstr(&buf), false);
75
+ git_str_dispose(&buf);
71
76
 
72
77
  if (!error && ce && ce->value) {
73
78
  if (!strcmp(ce->value, "--no-tags"))
@@ -99,7 +104,7 @@ static int ensure_remote_name_is_valid(const char *name)
99
104
  static int write_add_refspec(git_repository *repo, const char *name, const char *refspec, bool fetch)
100
105
  {
101
106
  git_config *cfg;
102
- git_buf var = GIT_BUF_INIT;
107
+ git_str var = GIT_STR_INIT;
103
108
  git_refspec spec;
104
109
  const char *fmt;
105
110
  int error;
@@ -117,7 +122,7 @@ static int write_add_refspec(git_repository *repo, const char *name, const char
117
122
 
118
123
  git_refspec__dispose(&spec);
119
124
 
120
- if ((error = git_buf_printf(&var, fmt, name)) < 0)
125
+ if ((error = git_str_printf(&var, fmt, name)) < 0)
121
126
  return error;
122
127
 
123
128
  /*
@@ -130,11 +135,11 @@ static int write_add_refspec(git_repository *repo, const char *name, const char
130
135
  }
131
136
 
132
137
  cleanup:
133
- git_buf_dispose(&var);
138
+ git_str_dispose(&var);
134
139
  return 0;
135
140
  }
136
141
 
137
- static int canonicalize_url(git_buf *out, const char *in)
142
+ static int canonicalize_url(git_str *out, const char *in)
138
143
  {
139
144
  if (in == NULL || strlen(in) == 0) {
140
145
  git_error_set(GIT_ERROR_INVALID, "cannot set empty URL");
@@ -149,18 +154,18 @@ static int canonicalize_url(git_buf *out, const char *in)
149
154
  (git__isalpha(in[2]) || git__isdigit(in[2]))) {
150
155
  const char *c;
151
156
  for (c = in; *c; c++)
152
- git_buf_putc(out, *c == '\\' ? '/' : *c);
157
+ git_str_putc(out, *c == '\\' ? '/' : *c);
153
158
 
154
- return git_buf_oom(out) ? -1 : 0;
159
+ return git_str_oom(out) ? -1 : 0;
155
160
  }
156
161
  #endif
157
162
 
158
- return git_buf_puts(out, in);
163
+ return git_str_puts(out, in);
159
164
  }
160
165
 
161
- static int default_fetchspec_for_name(git_buf *buf, const char *name)
166
+ static int default_fetchspec_for_name(git_str *buf, const char *name)
162
167
  {
163
- if (git_buf_printf(buf, "+refs/heads/*:refs/remotes/%s/*", name) < 0)
168
+ if (git_str_printf(buf, "+refs/heads/*:refs/remotes/%s/*", name) < 0)
164
169
  return -1;
165
170
 
166
171
  return 0;
@@ -204,9 +209,9 @@ int git_remote_create_with_opts(git_remote **out, const char *url, const git_rem
204
209
  {
205
210
  git_remote *remote = NULL;
206
211
  git_config *config_ro = NULL, *config_rw;
207
- git_buf canonical_url = GIT_BUF_INIT;
208
- git_buf var = GIT_BUF_INIT;
209
- git_buf specbuf = GIT_BUF_INIT;
212
+ git_str canonical_url = GIT_STR_INIT;
213
+ git_str var = GIT_STR_INIT;
214
+ git_str specbuf = GIT_STR_INIT;
210
215
  const git_remote_create_options dummy_opts = GIT_REMOTE_CREATE_OPTIONS_INIT;
211
216
  int error = -1;
212
217
 
@@ -243,18 +248,20 @@ int git_remote_create_with_opts(git_remote **out, const char *url, const git_rem
243
248
  goto on_error;
244
249
 
245
250
  if (opts->repository && !(opts->flags & GIT_REMOTE_CREATE_SKIP_INSTEADOF)) {
246
- remote->url = apply_insteadof(config_ro, canonical_url.ptr, GIT_DIRECTION_FETCH);
251
+ if ((error = apply_insteadof(&remote->url, config_ro, canonical_url.ptr, GIT_DIRECTION_FETCH, true)) < 0 ||
252
+ (error = apply_insteadof(&remote->pushurl, config_ro, canonical_url.ptr, GIT_DIRECTION_PUSH, false)) < 0)
253
+ goto on_error;
247
254
  } else {
248
255
  remote->url = git__strdup(canonical_url.ptr);
256
+ GIT_ERROR_CHECK_ALLOC(remote->url);
249
257
  }
250
- GIT_ERROR_CHECK_ALLOC(remote->url);
251
258
 
252
259
  if (opts->name != NULL) {
253
260
  remote->name = git__strdup(opts->name);
254
261
  GIT_ERROR_CHECK_ALLOC(remote->name);
255
262
 
256
263
  if (opts->repository &&
257
- ((error = git_buf_printf(&var, CONFIG_URL_FMT, opts->name)) < 0 ||
264
+ ((error = git_str_printf(&var, CONFIG_URL_FMT, opts->name)) < 0 ||
258
265
  (error = git_repository_config__weakptr(&config_rw, opts->repository)) < 0 ||
259
266
  (error = git_config_set_string(config_rw, var.ptr, canonical_url.ptr)) < 0))
260
267
  goto on_error;
@@ -269,7 +276,7 @@ int git_remote_create_with_opts(git_remote **out, const char *url, const git_rem
269
276
  if ((error = default_fetchspec_for_name(&specbuf, opts->name)) < 0)
270
277
  goto on_error;
271
278
 
272
- fetch = git_buf_cstr(&specbuf);
279
+ fetch = git_str_cstr(&specbuf);
273
280
  }
274
281
 
275
282
  if ((error = add_refspec(remote, fetch, true)) < 0)
@@ -293,7 +300,7 @@ int git_remote_create_with_opts(git_remote **out, const char *url, const git_rem
293
300
  remote->download_tags = GIT_REMOTE_DOWNLOAD_TAGS_AUTO;
294
301
 
295
302
 
296
- git_buf_dispose(&var);
303
+ git_str_dispose(&var);
297
304
 
298
305
  *out = remote;
299
306
  error = 0;
@@ -303,15 +310,15 @@ on_error:
303
310
  git_remote_free(remote);
304
311
 
305
312
  git_config_free(config_ro);
306
- git_buf_dispose(&specbuf);
307
- git_buf_dispose(&canonical_url);
308
- git_buf_dispose(&var);
313
+ git_str_dispose(&specbuf);
314
+ git_str_dispose(&canonical_url);
315
+ git_str_dispose(&var);
309
316
  return error;
310
317
  }
311
318
 
312
319
  int git_remote_create(git_remote **out, git_repository *repo, const char *name, const char *url)
313
320
  {
314
- git_buf buf = GIT_BUF_INIT;
321
+ git_str buf = GIT_STR_INIT;
315
322
  int error;
316
323
  git_remote_create_options opts = GIT_REMOTE_CREATE_OPTIONS_INIT;
317
324
 
@@ -322,14 +329,14 @@ int git_remote_create(git_remote **out, git_repository *repo, const char *name,
322
329
  if (canonicalize_url(&buf, url) < 0)
323
330
  return GIT_ERROR;
324
331
 
325
- git_buf_clear(&buf);
332
+ git_str_clear(&buf);
326
333
 
327
334
  opts.repository = repo;
328
335
  opts.name = name;
329
336
 
330
337
  error = git_remote_create_with_opts(out, url, &opts);
331
338
 
332
- git_buf_dispose(&buf);
339
+ git_str_dispose(&buf);
333
340
 
334
341
  return error;
335
342
  }
@@ -425,13 +432,13 @@ static int refspec_cb(const git_config_entry *entry, void *payload)
425
432
  }
426
433
 
427
434
  static int get_optional_config(
428
- bool *found, git_config *config, git_buf *buf,
435
+ bool *found, git_config *config, git_str *buf,
429
436
  git_config_foreach_cb cb, void *payload)
430
437
  {
431
438
  int error = 0;
432
- const char *key = git_buf_cstr(buf);
439
+ const char *key = git_str_cstr(buf);
433
440
 
434
- if (git_buf_oom(buf))
441
+ if (git_str_oom(buf))
435
442
  return -1;
436
443
 
437
444
  if (cb != NULL)
@@ -453,7 +460,7 @@ static int get_optional_config(
453
460
  int git_remote_lookup(git_remote **out, git_repository *repo, const char *name)
454
461
  {
455
462
  git_remote *remote = NULL;
456
- git_buf buf = GIT_BUF_INIT;
463
+ git_str buf = GIT_STR_INIT;
457
464
  const char *val;
458
465
  int error = 0;
459
466
  git_config *config;
@@ -484,7 +491,7 @@ int git_remote_lookup(git_remote **out, git_repository *repo, const char *name)
484
491
  goto cleanup;
485
492
  }
486
493
 
487
- if ((error = git_buf_printf(&buf, "remote.%s.url", name)) < 0)
494
+ if ((error = git_str_printf(&buf, "remote.%s.url", name)) < 0)
488
495
  goto cleanup;
489
496
 
490
497
  if ((error = get_optional_config(&found, config, &buf, NULL, (void *)&val)) < 0)
@@ -496,13 +503,14 @@ int git_remote_lookup(git_remote **out, git_repository *repo, const char *name)
496
503
  remote->download_tags = GIT_REMOTE_DOWNLOAD_TAGS_AUTO;
497
504
 
498
505
  if (found && strlen(val) > 0) {
499
- remote->url = apply_insteadof(config, val, GIT_DIRECTION_FETCH);
500
- GIT_ERROR_CHECK_ALLOC(remote->url);
506
+ if ((error = apply_insteadof(&remote->url, config, val, GIT_DIRECTION_FETCH, true)) < 0 ||
507
+ (error = apply_insteadof(&remote->pushurl, config, val, GIT_DIRECTION_PUSH, false)) < 0)
508
+ goto cleanup;
501
509
  }
502
510
 
503
511
  val = NULL;
504
- git_buf_clear(&buf);
505
- git_buf_printf(&buf, "remote.%s.pushurl", name);
512
+ git_str_clear(&buf);
513
+ git_str_printf(&buf, "remote.%s.pushurl", name);
506
514
 
507
515
  if ((error = get_optional_config(&found, config, &buf, NULL, (void *)&val)) < 0)
508
516
  goto cleanup;
@@ -516,22 +524,25 @@ int git_remote_lookup(git_remote **out, git_repository *repo, const char *name)
516
524
  }
517
525
 
518
526
  if (found && strlen(val) > 0) {
519
- remote->pushurl = apply_insteadof(config, val, GIT_DIRECTION_PUSH);
520
- GIT_ERROR_CHECK_ALLOC(remote->pushurl);
527
+ if (remote->pushurl)
528
+ git__free(remote->pushurl);
529
+
530
+ if ((error = apply_insteadof(&remote->pushurl, config, val, GIT_DIRECTION_FETCH, true)) < 0)
531
+ goto cleanup;
521
532
  }
522
533
 
523
534
  data.remote = remote;
524
535
  data.fetch = true;
525
536
 
526
- git_buf_clear(&buf);
527
- git_buf_printf(&buf, "remote.%s.fetch", name);
537
+ git_str_clear(&buf);
538
+ git_str_printf(&buf, "remote.%s.fetch", name);
528
539
 
529
540
  if ((error = get_optional_config(NULL, config, &buf, refspec_cb, &data)) < 0)
530
541
  goto cleanup;
531
542
 
532
543
  data.fetch = false;
533
- git_buf_clear(&buf);
534
- git_buf_printf(&buf, "remote.%s.push", name);
544
+ git_str_clear(&buf);
545
+ git_str_printf(&buf, "remote.%s.push", name);
535
546
 
536
547
  if ((error = get_optional_config(NULL, config, &buf, refspec_cb, &data)) < 0)
537
548
  goto cleanup;
@@ -550,7 +561,7 @@ int git_remote_lookup(git_remote **out, git_repository *repo, const char *name)
550
561
 
551
562
  cleanup:
552
563
  git_config_free(config);
553
- git_buf_dispose(&buf);
564
+ git_str_dispose(&buf);
554
565
 
555
566
  if (error < 0)
556
567
  git_remote_free(remote);
@@ -560,12 +571,12 @@ cleanup:
560
571
 
561
572
  static int lookup_remote_prune_config(git_remote *remote, git_config *config, const char *name)
562
573
  {
563
- git_buf buf = GIT_BUF_INIT;
574
+ git_str buf = GIT_STR_INIT;
564
575
  int error = 0;
565
576
 
566
- git_buf_printf(&buf, "remote.%s.prune", name);
577
+ git_str_printf(&buf, "remote.%s.prune", name);
567
578
 
568
- if ((error = git_config_get_bool(&remote->prune_refs, config, git_buf_cstr(&buf))) < 0) {
579
+ if ((error = git_config_get_bool(&remote->prune_refs, config, git_str_cstr(&buf))) < 0) {
569
580
  if (error == GIT_ENOTFOUND) {
570
581
  git_error_clear();
571
582
 
@@ -578,7 +589,7 @@ static int lookup_remote_prune_config(git_remote *remote, git_config *config, co
578
589
  }
579
590
  }
580
591
 
581
- git_buf_dispose(&buf);
592
+ git_str_dispose(&buf);
582
593
  return error;
583
594
  }
584
595
 
@@ -619,7 +630,7 @@ int git_remote_set_instance_url(git_remote *remote, const char *url)
619
630
  static int set_url(git_repository *repo, const char *remote, const char *pattern, const char *url)
620
631
  {
621
632
  git_config *cfg;
622
- git_buf buf = GIT_BUF_INIT, canonical_url = GIT_BUF_INIT;
633
+ git_str buf = GIT_STR_INIT, canonical_url = GIT_STR_INIT;
623
634
  int error;
624
635
 
625
636
  GIT_ASSERT_ARG(repo);
@@ -631,7 +642,7 @@ static int set_url(git_repository *repo, const char *remote, const char *pattern
631
642
  if ((error = git_repository_config__weakptr(&cfg, repo)) < 0)
632
643
  return error;
633
644
 
634
- if ((error = git_buf_printf(&buf, pattern, remote)) < 0)
645
+ if ((error = git_str_printf(&buf, pattern, remote)) < 0)
635
646
  return error;
636
647
 
637
648
  if (url) {
@@ -644,8 +655,8 @@ static int set_url(git_repository *repo, const char *remote, const char *pattern
644
655
  }
645
656
 
646
657
  cleanup:
647
- git_buf_dispose(&canonical_url);
648
- git_buf_dispose(&buf);
658
+ git_str_dispose(&canonical_url);
659
+ git_str_dispose(&buf);
649
660
 
650
661
  return error;
651
662
  }
@@ -683,7 +694,7 @@ int git_remote_set_pushurl(git_repository *repo, const char *remote, const char
683
694
  }
684
695
 
685
696
  static int resolve_url(
686
- git_buf *resolved_url,
697
+ git_str *resolved_url,
687
698
  const char *url,
688
699
  int direction,
689
700
  const git_remote_callbacks *callbacks)
@@ -692,27 +703,28 @@ static int resolve_url(
692
703
  GIT_UNUSED(direction);
693
704
  GIT_UNUSED(callbacks);
694
705
  #else
695
- int status, error;
706
+ git_buf buf = GIT_BUF_INIT;
707
+ int error;
696
708
 
697
709
  if (callbacks && callbacks->resolve_url) {
698
- git_buf_clear(resolved_url);
699
- status = callbacks->resolve_url(resolved_url, url, direction, callbacks->payload);
700
- if (status != GIT_PASSTHROUGH) {
701
- git_error_set_after_callback_function(status, "git_resolve_url_cb");
710
+ error = callbacks->resolve_url(&buf, url, direction, callbacks->payload);
702
711
 
703
- if ((error = git_buf_sanitize(resolved_url)) < 0)
704
- return error;
712
+ if (error != GIT_PASSTHROUGH) {
713
+ git_error_set_after_callback_function(error, "git_resolve_url_cb");
705
714
 
706
- return status;
715
+ git_str_set(resolved_url, buf.ptr, buf.size);
716
+ git_buf_dispose(&buf);
717
+
718
+ return error;
707
719
  }
708
720
  }
709
721
  #endif
710
722
 
711
- return git_buf_sets(resolved_url, url);
723
+ return git_str_sets(resolved_url, url);
712
724
  }
713
725
 
714
726
  int git_remote__urlfordirection(
715
- git_buf *url_out,
727
+ git_str *url_out,
716
728
  struct git_remote *remote,
717
729
  int direction,
718
730
  const git_remote_callbacks *callbacks)
@@ -747,54 +759,200 @@ int git_remote__urlfordirection(
747
759
  return resolve_url(url_out, url, direction, callbacks);
748
760
  }
749
761
 
750
- static int remote_transport_set_callbacks(git_transport *t, const git_remote_callbacks *cbs)
762
+ int git_remote_connect_options_init(
763
+ git_remote_connect_options *opts,
764
+ unsigned int version)
765
+ {
766
+ GIT_INIT_STRUCTURE_FROM_TEMPLATE(
767
+ opts, version, git_remote_connect_options, GIT_REMOTE_CONNECT_OPTIONS_INIT);
768
+ return 0;
769
+ }
770
+
771
+ int git_remote_connect_options_dup(
772
+ git_remote_connect_options *dst,
773
+ const git_remote_connect_options *src)
774
+ {
775
+ memcpy(dst, src, sizeof(git_remote_connect_options));
776
+
777
+ if (git_proxy_options_dup(&dst->proxy_opts, &src->proxy_opts) < 0 ||
778
+ git_strarray_copy(&dst->custom_headers, &src->custom_headers) < 0)
779
+ return -1;
780
+
781
+ return 0;
782
+ }
783
+
784
+ void git_remote_connect_options_dispose(git_remote_connect_options *opts)
785
+ {
786
+ if (!opts)
787
+ return;
788
+
789
+ git_strarray_dispose(&opts->custom_headers);
790
+ git_proxy_options_dispose(&opts->proxy_opts);
791
+ }
792
+
793
+ static size_t http_header_name_length(const char *http_header)
794
+ {
795
+ const char *colon = strchr(http_header, ':');
796
+ if (!colon)
797
+ return 0;
798
+ return colon - http_header;
799
+ }
800
+
801
+ static bool is_malformed_http_header(const char *http_header)
802
+ {
803
+ const char *c;
804
+ size_t name_len;
805
+
806
+ /* Disallow \r and \n */
807
+ if ((c = strchr(http_header, '\r')) != NULL)
808
+ return true;
809
+ if ((c = strchr(http_header, '\n')) != NULL)
810
+ return true;
811
+
812
+ /* Require a header name followed by : */
813
+ if ((name_len = http_header_name_length(http_header)) < 1)
814
+ return true;
815
+
816
+ return false;
817
+ }
818
+
819
+ static char *forbidden_custom_headers[] = {
820
+ "User-Agent",
821
+ "Host",
822
+ "Accept",
823
+ "Content-Type",
824
+ "Transfer-Encoding",
825
+ "Content-Length",
826
+ };
827
+
828
+ static bool is_forbidden_custom_header(const char *custom_header)
751
829
  {
752
- if (!t->set_callbacks || !cbs)
830
+ unsigned long i;
831
+ size_t name_len = http_header_name_length(custom_header);
832
+
833
+ /* Disallow headers that we set */
834
+ for (i = 0; i < ARRAY_SIZE(forbidden_custom_headers); i++)
835
+ if (strncmp(forbidden_custom_headers[i], custom_header, name_len) == 0)
836
+ return true;
837
+
838
+ return false;
839
+ }
840
+
841
+ static int validate_custom_headers(const git_strarray *custom_headers)
842
+ {
843
+ size_t i;
844
+
845
+ if (!custom_headers)
753
846
  return 0;
754
847
 
755
- return t->set_callbacks(t, cbs->sideband_progress, NULL,
756
- cbs->certificate_check, cbs->payload);
848
+ for (i = 0; i < custom_headers->count; i++) {
849
+ if (is_malformed_http_header(custom_headers->strings[i])) {
850
+ git_error_set(GIT_ERROR_INVALID, "custom HTTP header '%s' is malformed", custom_headers->strings[i]);
851
+ return -1;
852
+ }
853
+
854
+ if (is_forbidden_custom_header(custom_headers->strings[i])) {
855
+ git_error_set(GIT_ERROR_INVALID, "custom HTTP header '%s' is already set by libgit2", custom_headers->strings[i]);
856
+ return -1;
857
+ }
858
+ }
859
+
860
+ return 0;
757
861
  }
758
862
 
759
- static int set_transport_custom_headers(git_transport *t, const git_strarray *custom_headers)
863
+ static int lookup_redirect_config(
864
+ git_remote_redirect_t *out,
865
+ git_repository *repo)
760
866
  {
761
- if (!t->set_custom_headers)
867
+ git_config *config;
868
+ const char *value;
869
+ int bool_value, error = 0;
870
+
871
+ if (!repo) {
872
+ *out = GIT_REMOTE_REDIRECT_INITIAL;
762
873
  return 0;
874
+ }
875
+
876
+ if ((error = git_repository_config_snapshot(&config, repo)) < 0)
877
+ goto done;
878
+
879
+ if ((error = git_config_get_string(&value, config, "http.followRedirects")) < 0) {
880
+ if (error == GIT_ENOTFOUND) {
881
+ *out = GIT_REMOTE_REDIRECT_INITIAL;
882
+ error = 0;
883
+ }
884
+
885
+ goto done;
886
+ }
887
+
888
+ if (git_config_parse_bool(&bool_value, value) == 0) {
889
+ *out = bool_value ? GIT_REMOTE_REDIRECT_ALL :
890
+ GIT_REMOTE_REDIRECT_NONE;
891
+ } else if (strcasecmp(value, "initial") == 0) {
892
+ *out = GIT_REMOTE_REDIRECT_INITIAL;
893
+ } else {
894
+ git_error_set(GIT_ERROR_CONFIG, "invalid configuration setting '%s' for 'http.followRedirects'", value);
895
+ error = -1;
896
+ }
897
+
898
+ done:
899
+ git_config_free(config);
900
+ return error;
901
+ }
902
+
903
+ int git_remote_connect_options_normalize(
904
+ git_remote_connect_options *dst,
905
+ git_repository *repo,
906
+ const git_remote_connect_options *src)
907
+ {
908
+ git_remote_connect_options_dispose(dst);
909
+ git_remote_connect_options_init(dst, GIT_REMOTE_CONNECT_OPTIONS_VERSION);
910
+
911
+ if (src) {
912
+ GIT_ERROR_CHECK_VERSION(src, GIT_REMOTE_CONNECT_OPTIONS_VERSION, "git_remote_connect_options");
913
+ GIT_ERROR_CHECK_VERSION(&src->callbacks, GIT_REMOTE_CALLBACKS_VERSION, "git_remote_callbacks");
914
+ GIT_ERROR_CHECK_VERSION(&src->proxy_opts, GIT_PROXY_OPTIONS_VERSION, "git_proxy_options");
915
+
916
+ if (validate_custom_headers(&src->custom_headers) < 0 ||
917
+ git_remote_connect_options_dup(dst, src) < 0)
918
+ return -1;
919
+ }
763
920
 
764
- return t->set_custom_headers(t, custom_headers);
921
+ if (dst->follow_redirects == 0) {
922
+ if (lookup_redirect_config(&dst->follow_redirects, repo) < 0)
923
+ return -1;
924
+ }
925
+
926
+ return 0;
765
927
  }
766
928
 
767
- int git_remote__connect(git_remote *remote, git_direction direction, const git_remote_callbacks *callbacks, const git_remote_connection_opts *conn)
929
+ int git_remote_connect_ext(
930
+ git_remote *remote,
931
+ git_direction direction,
932
+ const git_remote_connect_options *given_opts)
768
933
  {
934
+ git_remote_connect_options opts = GIT_REMOTE_CONNECT_OPTIONS_INIT;
935
+ git_str url = GIT_STR_INIT;
769
936
  git_transport *t;
770
- git_buf url = GIT_BUF_INIT;
771
- int flags = GIT_TRANSPORTFLAGS_NONE;
772
937
  int error;
773
- void *payload = NULL;
774
- git_credential_acquire_cb credentials = NULL;
775
- git_transport_cb transport = NULL;
776
938
 
777
939
  GIT_ASSERT_ARG(remote);
778
940
 
779
- if (callbacks) {
780
- GIT_ERROR_CHECK_VERSION(callbacks, GIT_REMOTE_CALLBACKS_VERSION, "git_remote_callbacks");
781
- credentials = callbacks->credentials;
782
- transport = callbacks->transport;
783
- payload = callbacks->payload;
784
- }
941
+ if (given_opts)
942
+ memcpy(&opts, given_opts, sizeof(git_remote_connect_options));
785
943
 
786
- if (conn->proxy)
787
- GIT_ERROR_CHECK_VERSION(conn->proxy, GIT_PROXY_OPTIONS_VERSION, "git_proxy_options");
944
+ GIT_ERROR_CHECK_VERSION(&opts.callbacks, GIT_REMOTE_CALLBACKS_VERSION, "git_remote_callbacks");
945
+ GIT_ERROR_CHECK_VERSION(&opts.proxy_opts, GIT_PROXY_OPTIONS_VERSION, "git_proxy_options");
788
946
 
789
947
  t = remote->transport;
790
948
 
791
- if ((error = git_remote__urlfordirection(&url, remote, direction, callbacks)) < 0)
949
+ if ((error = git_remote__urlfordirection(&url, remote, direction, &opts.callbacks)) < 0)
792
950
  goto on_error;
793
951
 
794
952
  /* If we don't have a transport object yet, and the caller specified a
795
953
  * custom transport factory, use that */
796
- if (!t && transport &&
797
- (error = transport(&t, remote, payload)) < 0)
954
+ if (!t && opts.callbacks.transport &&
955
+ (error = opts.callbacks.transport(&t, remote, opts.callbacks.payload)) < 0)
798
956
  goto on_error;
799
957
 
800
958
  /* If we still don't have a transport, then use the global
@@ -802,16 +960,12 @@ int git_remote__connect(git_remote *remote, git_direction direction, const git_r
802
960
  if (!t && (error = git_transport_new(&t, remote, url.ptr)) < 0)
803
961
  goto on_error;
804
962
 
805
- if ((error = set_transport_custom_headers(t, conn->custom_headers)) != 0)
806
- goto on_error;
807
-
808
- if ((error = remote_transport_set_callbacks(t, callbacks)) < 0 ||
809
- (error = t->connect(t, url.ptr, credentials, payload, conn->proxy, direction, flags)) != 0)
963
+ if ((error = t->connect(t, url.ptr, direction, &opts)) != 0)
810
964
  goto on_error;
811
965
 
812
966
  remote->transport = t;
813
967
 
814
- git_buf_dispose(&url);
968
+ git_str_dispose(&url);
815
969
 
816
970
  return 0;
817
971
 
@@ -819,7 +973,7 @@ on_error:
819
973
  if (t)
820
974
  t->free(t);
821
975
 
822
- git_buf_dispose(&url);
976
+ git_str_dispose(&url);
823
977
 
824
978
  if (t == remote->transport)
825
979
  remote->transport = NULL;
@@ -827,14 +981,25 @@ on_error:
827
981
  return error;
828
982
  }
829
983
 
830
- int git_remote_connect(git_remote *remote, git_direction direction, const git_remote_callbacks *callbacks, const git_proxy_options *proxy, const git_strarray *custom_headers)
984
+ int git_remote_connect(
985
+ git_remote *remote,
986
+ git_direction direction,
987
+ const git_remote_callbacks *callbacks,
988
+ const git_proxy_options *proxy,
989
+ const git_strarray *custom_headers)
831
990
  {
832
- git_remote_connection_opts conn;
991
+ git_remote_connect_options opts = GIT_REMOTE_CONNECT_OPTIONS_INIT;
992
+
993
+ if (callbacks)
994
+ memcpy(&opts.callbacks, callbacks, sizeof(git_remote_callbacks));
833
995
 
834
- conn.proxy = proxy;
835
- conn.custom_headers = custom_headers;
996
+ if (proxy)
997
+ memcpy(&opts.proxy_opts, proxy, sizeof(git_proxy_options));
836
998
 
837
- return git_remote__connect(remote, direction, callbacks, &conn);
999
+ if (custom_headers)
1000
+ memcpy(&opts.custom_headers, custom_headers, sizeof(git_strarray));
1001
+
1002
+ return git_remote_connect_ext(remote, direction, &opts);
838
1003
  }
839
1004
 
840
1005
  int git_remote_ls(const git_remote_head ***out, size_t *size, git_remote *remote)
@@ -849,6 +1014,38 @@ int git_remote_ls(const git_remote_head ***out, size_t *size, git_remote *remote
849
1014
  return remote->transport->ls(out, size, remote->transport);
850
1015
  }
851
1016
 
1017
+ int git_remote_capabilities(unsigned int *out, git_remote *remote)
1018
+ {
1019
+ GIT_ASSERT_ARG(remote);
1020
+
1021
+ *out = 0;
1022
+
1023
+ if (!remote->transport) {
1024
+ git_error_set(GIT_ERROR_NET, "this remote has never connected");
1025
+ return -1;
1026
+ }
1027
+
1028
+ return remote->transport->capabilities(out, remote->transport);
1029
+ }
1030
+
1031
+ int git_remote_oid_type(git_oid_t *out, git_remote *remote)
1032
+ {
1033
+ GIT_ASSERT_ARG(remote);
1034
+
1035
+ if (!remote->transport) {
1036
+ git_error_set(GIT_ERROR_NET, "this remote has never connected");
1037
+ *out = 0;
1038
+ return -1;
1039
+ }
1040
+
1041
+ #ifdef GIT_EXPERIMENTAL_SHA256
1042
+ return remote->transport->oid_type(out, remote->transport);
1043
+ #else
1044
+ *out = GIT_OID_SHA1;
1045
+ return 0;
1046
+ #endif
1047
+ }
1048
+
852
1049
  static int lookup_config(char **out, git_config *cfg, const char *name)
853
1050
  {
854
1051
  git_config_entry *ce = NULL;
@@ -885,7 +1082,7 @@ static void url_config_trim(git_net_url *url)
885
1082
  static int http_proxy_config(char **out, git_remote *remote, git_net_url *url)
886
1083
  {
887
1084
  git_config *cfg = NULL;
888
- git_buf buf = GIT_BUF_INIT;
1085
+ git_str buf = GIT_STR_INIT;
889
1086
  git_net_url lookup_url = GIT_NET_URL_INIT;
890
1087
  int error;
891
1088
 
@@ -902,19 +1099,19 @@ static int http_proxy_config(char **out, git_remote *remote, git_net_url *url)
902
1099
 
903
1100
  /* remote.<name>.proxy config setting */
904
1101
  if (remote->name && remote->name[0]) {
905
- git_buf_clear(&buf);
1102
+ git_str_clear(&buf);
906
1103
 
907
- if ((error = git_buf_printf(&buf, "remote.%s.proxy", remote->name)) < 0 ||
1104
+ if ((error = git_str_printf(&buf, "remote.%s.proxy", remote->name)) < 0 ||
908
1105
  (error = lookup_config(out, cfg, buf.ptr)) != GIT_ENOTFOUND)
909
1106
  goto done;
910
1107
  }
911
1108
 
912
1109
  while (true) {
913
- git_buf_clear(&buf);
1110
+ git_str_clear(&buf);
914
1111
 
915
- if ((error = git_buf_puts(&buf, "http.")) < 0 ||
1112
+ if ((error = git_str_puts(&buf, "http.")) < 0 ||
916
1113
  (error = git_net_url_fmt(&buf, &lookup_url)) < 0 ||
917
- (error = git_buf_puts(&buf, ".proxy")) < 0 ||
1114
+ (error = git_str_puts(&buf, ".proxy")) < 0 ||
918
1115
  (error = lookup_config(out, cfg, buf.ptr)) != GIT_ENOTFOUND)
919
1116
  goto done;
920
1117
 
@@ -924,20 +1121,20 @@ static int http_proxy_config(char **out, git_remote *remote, git_net_url *url)
924
1121
  url_config_trim(&lookup_url);
925
1122
  }
926
1123
 
927
- git_buf_clear(&buf);
1124
+ git_str_clear(&buf);
928
1125
 
929
1126
  error = lookup_config(out, cfg, "http.proxy");
930
1127
 
931
1128
  done:
932
1129
  git_config_free(cfg);
933
- git_buf_dispose(&buf);
1130
+ git_str_dispose(&buf);
934
1131
  git_net_url_dispose(&lookup_url);
935
1132
  return error;
936
1133
  }
937
1134
 
938
1135
  static int http_proxy_env(char **out, git_remote *remote, git_net_url *url)
939
1136
  {
940
- git_buf proxy_env = GIT_BUF_INIT, no_proxy_env = GIT_BUF_INIT;
1137
+ git_str proxy_env = GIT_STR_INIT, no_proxy_env = GIT_STR_INIT;
941
1138
  bool use_ssl = (strcmp(url->scheme, "https") == 0);
942
1139
  int error;
943
1140
 
@@ -963,13 +1160,13 @@ static int http_proxy_env(char **out, git_remote *remote, git_net_url *url)
963
1160
  goto done;
964
1161
 
965
1162
  if (!git_net_url_matches_pattern_list(url, no_proxy_env.ptr))
966
- *out = git_buf_detach(&proxy_env);
1163
+ *out = git_str_detach(&proxy_env);
967
1164
  else
968
1165
  error = GIT_ENOTFOUND;
969
1166
 
970
1167
  done:
971
- git_buf_dispose(&proxy_env);
972
- git_buf_dispose(&no_proxy_env);
1168
+ git_str_dispose(&proxy_env);
1169
+ git_str_dispose(&no_proxy_env);
973
1170
  return error;
974
1171
  }
975
1172
 
@@ -1048,38 +1245,32 @@ static int ls_to_vector(git_vector *out, git_remote *remote)
1048
1245
  return 0;
1049
1246
  }
1050
1247
 
1051
- int git_remote_download(git_remote *remote, const git_strarray *refspecs, const git_fetch_options *opts)
1248
+ static int connect_or_reset_options(
1249
+ git_remote *remote,
1250
+ int direction,
1251
+ git_remote_connect_options *opts)
1052
1252
  {
1053
- int error = -1;
1054
- size_t i;
1055
- git_vector *to_active, specs = GIT_VECTOR_INIT, refs = GIT_VECTOR_INIT;
1056
- const git_remote_callbacks *cbs = NULL;
1057
- const git_strarray *custom_headers = NULL;
1058
- const git_proxy_options *proxy = NULL;
1059
-
1060
- GIT_ASSERT_ARG(remote);
1061
-
1062
- if (!remote->repo) {
1063
- git_error_set(GIT_ERROR_INVALID, "cannot download detached remote");
1064
- return -1;
1065
- }
1066
-
1067
- if (opts) {
1068
- GIT_ERROR_CHECK_VERSION(&opts->callbacks, GIT_REMOTE_CALLBACKS_VERSION, "git_remote_callbacks");
1069
- cbs = &opts->callbacks;
1070
- custom_headers = &opts->custom_headers;
1071
- GIT_ERROR_CHECK_VERSION(&opts->proxy_opts, GIT_PROXY_OPTIONS_VERSION, "git_proxy_options");
1072
- proxy = &opts->proxy_opts;
1253
+ if (!git_remote_connected(remote)) {
1254
+ return git_remote_connect_ext(remote, direction, opts);
1255
+ } else {
1256
+ return remote->transport->set_connect_opts(remote->transport, opts);
1073
1257
  }
1258
+ }
1074
1259
 
1075
- if (!git_remote_connected(remote) &&
1076
- (error = git_remote_connect(remote, GIT_DIRECTION_FETCH, cbs, proxy, custom_headers)) < 0)
1077
- goto on_error;
1260
+ /* Download from an already connected remote. */
1261
+ static int git_remote__download(
1262
+ git_remote *remote,
1263
+ const git_strarray *refspecs,
1264
+ const git_fetch_options *opts)
1265
+ {
1266
+ git_vector *to_active, specs = GIT_VECTOR_INIT, refs = GIT_VECTOR_INIT;
1267
+ size_t i;
1268
+ int error;
1078
1269
 
1079
1270
  if (ls_to_vector(&refs, remote) < 0)
1080
1271
  return -1;
1081
1272
 
1082
- if ((git_vector_init(&specs, 0, NULL)) < 0)
1273
+ if ((error = git_vector_init(&specs, 0, NULL)) < 0)
1083
1274
  goto on_error;
1084
1275
 
1085
1276
  remote->passed_refspecs = 0;
@@ -1102,12 +1293,12 @@ int git_remote_download(git_remote *remote, const git_strarray *refspecs, const
1102
1293
  free_refspecs(&remote->active_refspecs);
1103
1294
  error = dwim_refspecs(&remote->active_refspecs, to_active, &refs);
1104
1295
 
1105
- git_vector_free(&refs);
1296
+ git_vector_dispose(&refs);
1106
1297
  free_refspecs(&specs);
1107
- git_vector_free(&specs);
1298
+ git_vector_dispose(&specs);
1108
1299
 
1109
1300
  if (error < 0)
1110
- return error;
1301
+ goto on_error;
1111
1302
 
1112
1303
  if (remote->push) {
1113
1304
  git_push_free(remote->push);
@@ -1115,66 +1306,113 @@ int git_remote_download(git_remote *remote, const git_strarray *refspecs, const
1115
1306
  }
1116
1307
 
1117
1308
  if ((error = git_fetch_negotiate(remote, opts)) < 0)
1118
- return error;
1309
+ goto on_error;
1119
1310
 
1120
- return git_fetch_download_pack(remote, cbs);
1311
+ error = git_fetch_download_pack(remote);
1121
1312
 
1122
1313
  on_error:
1123
- git_vector_free(&refs);
1314
+ git_vector_dispose(&refs);
1124
1315
  free_refspecs(&specs);
1125
- git_vector_free(&specs);
1316
+ git_vector_dispose(&specs);
1317
+ return error;
1318
+ }
1319
+
1320
+ int git_remote_download(
1321
+ git_remote *remote,
1322
+ const git_strarray *refspecs,
1323
+ const git_fetch_options *opts)
1324
+ {
1325
+ git_remote_connect_options connect_opts = GIT_REMOTE_CONNECT_OPTIONS_INIT;
1326
+ int error;
1327
+
1328
+ GIT_ASSERT_ARG(remote);
1329
+
1330
+ if (!remote->repo) {
1331
+ git_error_set(GIT_ERROR_INVALID, "cannot download detached remote");
1332
+ return -1;
1333
+ }
1334
+
1335
+ if (git_remote_connect_options__from_fetch_opts(&connect_opts,
1336
+ remote, opts) < 0)
1337
+ return -1;
1338
+
1339
+ if ((error = connect_or_reset_options(remote, GIT_DIRECTION_FETCH, &connect_opts)) < 0)
1340
+ return error;
1341
+
1342
+ error = git_remote__download(remote, refspecs, opts);
1343
+
1344
+ git_remote_connect_options_dispose(&connect_opts);
1345
+
1126
1346
  return error;
1127
1347
  }
1128
1348
 
1129
1349
  int git_remote_fetch(
1130
- git_remote *remote,
1131
- const git_strarray *refspecs,
1132
- const git_fetch_options *opts,
1133
- const char *reflog_message)
1350
+ git_remote *remote,
1351
+ const git_strarray *refspecs,
1352
+ const git_fetch_options *opts,
1353
+ const char *reflog_message)
1134
1354
  {
1135
- int error, update_fetchhead = 1;
1136
1355
  git_remote_autotag_option_t tagopt = remote->download_tags;
1137
1356
  bool prune = false;
1138
- git_buf reflog_msg_buf = GIT_BUF_INIT;
1139
- const git_remote_callbacks *cbs = NULL;
1140
- git_remote_connection_opts conn = GIT_REMOTE_CONNECTION_OPTIONS_INIT;
1357
+ git_str reflog_msg_buf = GIT_STR_INIT;
1358
+ git_remote_connect_options connect_opts = GIT_REMOTE_CONNECT_OPTIONS_INIT;
1359
+ unsigned int capabilities;
1360
+ git_oid_t oid_type;
1361
+ unsigned int update_flags = GIT_REMOTE_UPDATE_FETCHHEAD;
1362
+ int error;
1363
+
1364
+ GIT_ASSERT_ARG(remote);
1365
+
1366
+ if (!remote->repo) {
1367
+ git_error_set(GIT_ERROR_INVALID, "cannot download detached remote");
1368
+ return -1;
1369
+ }
1370
+
1371
+ if (git_remote_connect_options__from_fetch_opts(&connect_opts,
1372
+ remote, opts) < 0)
1373
+ return -1;
1374
+
1375
+ if ((error = connect_or_reset_options(remote, GIT_DIRECTION_FETCH, &connect_opts)) < 0)
1376
+ return error;
1141
1377
 
1142
1378
  if (opts) {
1143
- GIT_ERROR_CHECK_VERSION(&opts->callbacks, GIT_REMOTE_CALLBACKS_VERSION, "git_remote_callbacks");
1144
- cbs = &opts->callbacks;
1145
- conn.custom_headers = &opts->custom_headers;
1146
- update_fetchhead = opts->update_fetchhead;
1379
+ update_flags = opts->update_fetchhead;
1147
1380
  tagopt = opts->download_tags;
1148
- GIT_ERROR_CHECK_VERSION(&opts->proxy_opts, GIT_PROXY_OPTIONS_VERSION, "git_proxy_options");
1149
- conn.proxy = &opts->proxy_opts;
1150
1381
  }
1151
1382
 
1152
- /* Connect and download everything */
1153
- if ((error = git_remote__connect(remote, GIT_DIRECTION_FETCH, cbs, &conn)) != 0)
1383
+ if ((error = git_remote_capabilities(&capabilities, remote)) < 0 ||
1384
+ (error = git_remote_oid_type(&oid_type, remote)) < 0)
1154
1385
  return error;
1155
1386
 
1156
- error = git_remote_download(remote, refspecs, opts);
1387
+ /* Connect and download everything */
1388
+ error = git_remote__download(remote, refspecs, opts);
1157
1389
 
1158
1390
  /* We don't need to be connected anymore */
1159
1391
  git_remote_disconnect(remote);
1160
1392
 
1161
1393
  /* If the download failed, return the error */
1162
1394
  if (error != 0)
1163
- return error;
1395
+ goto done;
1164
1396
 
1165
1397
  /* Default reflog message */
1166
1398
  if (reflog_message)
1167
- git_buf_sets(&reflog_msg_buf, reflog_message);
1399
+ git_str_sets(&reflog_msg_buf, reflog_message);
1168
1400
  else {
1169
- git_buf_printf(&reflog_msg_buf, "fetch %s",
1401
+ git_str_printf(&reflog_msg_buf, "fetch %s",
1170
1402
  remote->name ? remote->name : remote->url);
1171
1403
  }
1172
1404
 
1173
1405
  /* Create "remote/foo" branches for all remote branches */
1174
- error = git_remote_update_tips(remote, cbs, update_fetchhead, tagopt, git_buf_cstr(&reflog_msg_buf));
1175
- git_buf_dispose(&reflog_msg_buf);
1406
+ error = git_remote_update_tips(remote,
1407
+ &connect_opts.callbacks,
1408
+ update_flags,
1409
+ tagopt,
1410
+ git_str_cstr(&reflog_msg_buf));
1411
+
1412
+ git_str_dispose(&reflog_msg_buf);
1413
+
1176
1414
  if (error < 0)
1177
- return error;
1415
+ goto done;
1178
1416
 
1179
1417
  if (opts && opts->prune == GIT_FETCH_PRUNE)
1180
1418
  prune = true;
@@ -1186,8 +1424,10 @@ int git_remote_fetch(
1186
1424
  prune = remote->prune_refs;
1187
1425
 
1188
1426
  if (prune)
1189
- error = git_remote_prune(remote, cbs);
1427
+ error = git_remote_prune(remote, &connect_opts.callbacks);
1190
1428
 
1429
+ done:
1430
+ git_remote_connect_options_dispose(&connect_opts);
1191
1431
  return error;
1192
1432
  }
1193
1433
 
@@ -1211,22 +1451,22 @@ static int remote_head_for_fetchspec_src(git_remote_head **out, git_vector *upda
1211
1451
  return 0;
1212
1452
  }
1213
1453
 
1214
- static int ref_to_update(int *update, git_buf *remote_name, git_remote *remote, git_refspec *spec, const char *ref_name)
1454
+ static int ref_to_update(int *update, git_str *remote_name, git_remote *remote, git_refspec *spec, const char *ref_name)
1215
1455
  {
1216
1456
  int error = 0;
1217
1457
  git_repository *repo;
1218
- git_buf upstream_remote = GIT_BUF_INIT;
1219
- git_buf upstream_name = GIT_BUF_INIT;
1458
+ git_str upstream_remote = GIT_STR_INIT;
1459
+ git_str upstream_name = GIT_STR_INIT;
1220
1460
 
1221
1461
  repo = git_remote_owner(remote);
1222
1462
 
1223
1463
  if ((!git_reference__is_branch(ref_name)) ||
1224
1464
  !git_remote_name(remote) ||
1225
- (error = git_branch_upstream_remote(&upstream_remote, repo, ref_name) < 0) ||
1226
- git__strcmp(git_remote_name(remote), git_buf_cstr(&upstream_remote)) ||
1227
- (error = git_branch_upstream_name(&upstream_name, repo, ref_name)) < 0 ||
1228
- !git_refspec_dst_matches(spec, git_buf_cstr(&upstream_name)) ||
1229
- (error = git_refspec_rtransform(remote_name, spec, upstream_name.ptr)) < 0) {
1465
+ (error = git_branch__upstream_remote(&upstream_remote, repo, ref_name) < 0) ||
1466
+ git__strcmp(git_remote_name(remote), git_str_cstr(&upstream_remote)) ||
1467
+ (error = git_branch__upstream_name(&upstream_name, repo, ref_name)) < 0 ||
1468
+ !git_refspec_dst_matches(spec, git_str_cstr(&upstream_name)) ||
1469
+ (error = git_refspec__rtransform(remote_name, spec, upstream_name.ptr)) < 0) {
1230
1470
  /* Not an error if there is no upstream */
1231
1471
  if (error == GIT_ENOTFOUND) {
1232
1472
  git_error_clear();
@@ -1238,15 +1478,15 @@ static int ref_to_update(int *update, git_buf *remote_name, git_remote *remote,
1238
1478
  *update = 1;
1239
1479
  }
1240
1480
 
1241
- git_buf_dispose(&upstream_remote);
1242
- git_buf_dispose(&upstream_name);
1481
+ git_str_dispose(&upstream_remote);
1482
+ git_str_dispose(&upstream_name);
1243
1483
  return error;
1244
1484
  }
1245
1485
 
1246
1486
  static int remote_head_for_ref(git_remote_head **out, git_remote *remote, git_refspec *spec, git_vector *update_heads, git_reference *ref)
1247
1487
  {
1248
1488
  git_reference *resolved_ref = NULL;
1249
- git_buf remote_name = GIT_BUF_INIT;
1489
+ git_str remote_name = GIT_STR_INIT;
1250
1490
  git_config *config = NULL;
1251
1491
  const char *ref_name;
1252
1492
  int error = 0, update;
@@ -1281,10 +1521,10 @@ static int remote_head_for_ref(git_remote_head **out, git_remote *remote, git_re
1281
1521
  goto cleanup;
1282
1522
 
1283
1523
  if (update)
1284
- error = remote_head_for_fetchspec_src(out, update_heads, git_buf_cstr(&remote_name));
1524
+ error = remote_head_for_fetchspec_src(out, update_heads, git_str_cstr(&remote_name));
1285
1525
 
1286
1526
  cleanup:
1287
- git_buf_dispose(&remote_name);
1527
+ git_str_dispose(&remote_name);
1288
1528
  git_reference_free(resolved_ref);
1289
1529
  git_config_free(config);
1290
1530
  return error;
@@ -1349,7 +1589,7 @@ cleanup:
1349
1589
  for (i = 0; i < fetchhead_refs.length; ++i)
1350
1590
  git_fetchhead_ref_free(fetchhead_refs.contents[i]);
1351
1591
 
1352
- git_vector_free(&fetchhead_refs);
1592
+ git_vector_dispose(&fetchhead_refs);
1353
1593
  git_reference_free(head_ref);
1354
1594
 
1355
1595
  return error;
@@ -1403,7 +1643,10 @@ int git_remote_prune(git_remote *remote, const git_remote_callbacks *callbacks)
1403
1643
  const git_refspec *spec;
1404
1644
  const char *refname;
1405
1645
  int error;
1406
- git_oid zero_id = {{ 0 }};
1646
+ git_oid zero_id;
1647
+
1648
+ GIT_ASSERT(remote && remote->repo);
1649
+ git_oid_clear(&zero_id, remote->repo->oid_type);
1407
1650
 
1408
1651
  if (callbacks)
1409
1652
  GIT_ERROR_CHECK_VERSION(callbacks, GIT_REMOTE_CALLBACKS_VERSION, "git_remote_callbacks");
@@ -1422,7 +1665,7 @@ int git_remote_prune(git_remote *remote, const git_remote_callbacks *callbacks)
1422
1665
  */
1423
1666
  git_vector_foreach(&candidates, i, refname) {
1424
1667
  git_vector_foreach(&remote->active_refspecs, j, spec) {
1425
- git_buf buf = GIT_BUF_INIT;
1668
+ git_str buf = GIT_STR_INIT;
1426
1669
  size_t pos;
1427
1670
  char *src_name;
1428
1671
  git_remote_head key = {0};
@@ -1430,12 +1673,12 @@ int git_remote_prune(git_remote *remote, const git_remote_callbacks *callbacks)
1430
1673
  if (!git_refspec_dst_matches(spec, refname))
1431
1674
  continue;
1432
1675
 
1433
- if ((error = git_refspec_rtransform(&buf, spec, refname)) < 0)
1676
+ if ((error = git_refspec__rtransform(&buf, spec, refname)) < 0)
1434
1677
  goto cleanup;
1435
1678
 
1436
- key.name = (char *) git_buf_cstr(&buf);
1679
+ key.name = (char *) git_str_cstr(&buf);
1437
1680
  error = git_vector_bsearch(&pos, &remote_refs, &key);
1438
- git_buf_dispose(&buf);
1681
+ git_str_dispose(&buf);
1439
1682
 
1440
1683
  if (error < 0 && error != GIT_ENOTFOUND)
1441
1684
  goto cleanup;
@@ -1481,157 +1724,266 @@ int git_remote_prune(git_remote *remote, const git_remote_callbacks *callbacks)
1481
1724
  git_oid_cpy(&id, git_reference_target(ref));
1482
1725
  error = git_reference_delete(ref);
1483
1726
  git_reference_free(ref);
1727
+
1484
1728
  if (error < 0)
1485
1729
  goto cleanup;
1486
1730
 
1487
- if (callbacks && callbacks->update_tips)
1488
- error = callbacks->update_tips(refname, &id, &zero_id, callbacks->payload);
1731
+ if (callbacks && callbacks->update_refs)
1732
+ error = callbacks->update_refs(refname, &id,
1733
+ &zero_id, NULL, callbacks->payload);
1734
+ #ifndef GIT_DEPRECATE_HARD
1735
+ else if (callbacks && callbacks->update_tips)
1736
+ error = callbacks->update_tips(refname, &id,
1737
+ &zero_id, callbacks->payload);
1738
+ #endif
1489
1739
 
1490
- if (error < 0)
1740
+ if (error < 0) {
1741
+ git_error_set_after_callback_function(error, "git_remote_fetch");
1491
1742
  goto cleanup;
1743
+ }
1492
1744
  }
1493
1745
 
1494
1746
  cleanup:
1495
- git_vector_free(&remote_refs);
1496
- git_vector_free_deep(&candidates);
1747
+ git_vector_dispose(&remote_refs);
1748
+ git_vector_dispose_deep(&candidates);
1497
1749
  return error;
1498
1750
  }
1499
1751
 
1500
- static int update_tips_for_spec(
1501
- git_remote *remote,
1502
- const git_remote_callbacks *callbacks,
1503
- int update_fetchhead,
1504
- git_remote_autotag_option_t tagopt,
1505
- git_refspec *spec,
1506
- git_vector *refs,
1507
- const char *log_message)
1508
- {
1509
- int error = 0, autotag, valid;
1510
- unsigned int i = 0;
1511
- git_buf refname = GIT_BUF_INIT;
1512
- git_oid old;
1513
- git_odb *odb;
1514
- git_remote_head *head;
1752
+ static int update_ref(
1753
+ const git_remote *remote,
1754
+ const char *ref_name,
1755
+ git_oid *id,
1756
+ git_refspec *spec,
1757
+ const char *msg,
1758
+ const git_remote_callbacks *callbacks)
1759
+ {
1515
1760
  git_reference *ref;
1516
- git_refspec tagspec;
1517
- git_vector update_heads;
1761
+ git_oid old_id;
1762
+ int error;
1518
1763
 
1519
- GIT_ASSERT_ARG(remote);
1764
+ GIT_ASSERT(remote && remote->repo);
1765
+ git_oid_clear(&old_id, remote->repo->oid_type);
1520
1766
 
1521
- if (git_repository_odb__weakptr(&odb, remote->repo) < 0)
1522
- return -1;
1767
+ error = git_reference_name_to_id(&old_id, remote->repo, ref_name);
1523
1768
 
1524
- if (git_refspec__parse(&tagspec, GIT_REFSPEC_TAGS, true) < 0)
1525
- return -1;
1769
+ if (error < 0 && error != GIT_ENOTFOUND)
1770
+ return error;
1771
+ else if (error == 0 && git_oid_equal(&old_id, id))
1772
+ return 0;
1526
1773
 
1527
- /* Make a copy of the transport's refs */
1528
- if (git_vector_init(&update_heads, 16, NULL) < 0)
1529
- return -1;
1774
+ /* If we did find a current reference, make sure we haven't lost a race */
1775
+ if (error)
1776
+ error = git_reference_create(&ref, remote->repo, ref_name, id, true, msg);
1777
+ else
1778
+ error = git_reference_create_matching(&ref, remote->repo, ref_name, id, true, &old_id, msg);
1530
1779
 
1531
- for (; i < refs->length; ++i) {
1532
- head = git_vector_get(refs, i);
1533
- autotag = 0;
1534
- git_buf_clear(&refname);
1780
+ git_reference_free(ref);
1535
1781
 
1536
- /* Ignore malformed ref names (which also saves us from tag^{} */
1537
- if (git_reference_name_is_valid(&valid, head->name) < 0)
1538
- goto on_error;
1782
+ if (error < 0)
1783
+ return error;
1539
1784
 
1540
- if (!valid)
1541
- continue;
1785
+ if (callbacks && callbacks->update_refs)
1786
+ error = callbacks->update_refs(ref_name, &old_id,
1787
+ id, spec, callbacks->payload);
1788
+ #ifndef GIT_DEPRECATE_HARD
1789
+ else if (callbacks && callbacks->update_tips)
1790
+ error = callbacks->update_tips(ref_name, &old_id,
1791
+ id, callbacks->payload);
1792
+ #endif
1542
1793
 
1543
- /* If we have a tag, see if the auto-follow rules say to update it */
1544
- if (git_refspec_src_matches(&tagspec, head->name)) {
1545
- if (tagopt != GIT_REMOTE_DOWNLOAD_TAGS_NONE) {
1794
+ if (error < 0) {
1795
+ git_error_set_after_callback_function(error, "git_remote_fetch");
1796
+ return error;
1797
+ }
1546
1798
 
1547
- if (tagopt == GIT_REMOTE_DOWNLOAD_TAGS_AUTO)
1548
- autotag = 1;
1799
+ return 0;
1800
+ }
1549
1801
 
1550
- git_buf_clear(&refname);
1551
- if (git_buf_puts(&refname, head->name) < 0)
1552
- goto on_error;
1553
- }
1554
- }
1802
+ static int update_one_tip(
1803
+ git_vector *update_heads,
1804
+ git_remote *remote,
1805
+ git_refspec *spec,
1806
+ git_remote_head *head,
1807
+ git_refspec *tagspec,
1808
+ unsigned int update_flags,
1809
+ git_remote_autotag_option_t tagopt,
1810
+ const char *log_message,
1811
+ const git_remote_callbacks *callbacks)
1812
+ {
1813
+ git_odb *odb;
1814
+ git_str refname = GIT_STR_INIT;
1815
+ git_reference *ref = NULL;
1816
+ bool autotag = false, updated = false;
1817
+ git_oid old;
1818
+ int valid;
1819
+ int error;
1555
1820
 
1556
- /* If we didn't want to auto-follow the tag, check if the refspec matches */
1557
- if (!autotag && git_refspec_src_matches(spec, head->name)) {
1558
- if (spec->dst) {
1559
- if (git_refspec_transform(&refname, spec, head->name) < 0)
1560
- goto on_error;
1561
- } else {
1562
- /*
1563
- * no rhs mans store it in FETCH_HEAD, even if we don't
1564
- update anything else.
1565
- */
1566
- if ((error = git_vector_insert(&update_heads, head)) < 0)
1567
- goto on_error;
1821
+ GIT_ASSERT(remote && remote->repo);
1568
1822
 
1569
- continue;
1570
- }
1823
+ if ((error = git_repository_odb__weakptr(&odb, remote->repo)) < 0)
1824
+ goto done;
1825
+
1826
+ /* Ignore malformed ref names (which also saves us from tag^{} */
1827
+ if ((error = git_reference_name_is_valid(&valid, head->name)) < 0)
1828
+ goto done;
1829
+
1830
+ if (!valid)
1831
+ goto done;
1832
+
1833
+ /* If we have a tag, see if the auto-follow rules say to update it */
1834
+ if (git_refspec_src_matches(tagspec, head->name)) {
1835
+ if (tagopt == GIT_REMOTE_DOWNLOAD_TAGS_AUTO)
1836
+ autotag = true;
1837
+
1838
+ if (tagopt != GIT_REMOTE_DOWNLOAD_TAGS_NONE) {
1839
+ if (git_str_puts(&refname, head->name) < 0)
1840
+ goto done;
1571
1841
  }
1842
+ }
1572
1843
 
1573
- /* If we still don't have a refname, we don't want it */
1574
- if (git_buf_len(&refname) == 0) {
1575
- continue;
1844
+ /* If we didn't want to auto-follow the tag, check if the refspec matches */
1845
+ if (!autotag && git_refspec_src_matches(spec, head->name)) {
1846
+ if (spec->dst) {
1847
+ if ((error = git_refspec__transform(&refname, spec, head->name)) < 0)
1848
+ goto done;
1849
+ } else {
1850
+ /*
1851
+ * no rhs means store it in FETCH_HEAD, even if we don't
1852
+ * update anything else.
1853
+ */
1854
+ error = git_vector_insert(update_heads, head);
1855
+ goto done;
1576
1856
  }
1857
+ }
1577
1858
 
1578
- /* In autotag mode, only create tags for objects already in db */
1579
- if (autotag && !git_odb_exists(odb, &head->oid))
1580
- continue;
1859
+ /* If we still don't have a refname, we don't want it */
1860
+ if (git_str_len(&refname) == 0)
1861
+ goto done;
1581
1862
 
1582
- if (!autotag && git_vector_insert(&update_heads, head) < 0)
1583
- goto on_error;
1863
+ /* In autotag mode, only create tags for objects already in db */
1864
+ if (autotag && !git_odb_exists(odb, &head->oid))
1865
+ goto done;
1584
1866
 
1585
- error = git_reference_name_to_id(&old, remote->repo, refname.ptr);
1586
- if (error < 0 && error != GIT_ENOTFOUND)
1587
- goto on_error;
1867
+ if (!autotag && (error = git_vector_insert(update_heads, head)) < 0)
1868
+ goto done;
1588
1869
 
1589
- if (!(error || error == GIT_ENOTFOUND)
1590
- && !spec->force
1591
- && !git_graph_descendant_of(remote->repo, &head->oid, &old))
1592
- continue;
1870
+ error = git_reference_name_to_id(&old, remote->repo, refname.ptr);
1593
1871
 
1594
- if (error == GIT_ENOTFOUND) {
1595
- memset(&old, 0, GIT_OID_RAWSZ);
1872
+ if (error < 0 && error != GIT_ENOTFOUND)
1873
+ goto done;
1596
1874
 
1597
- if (autotag && git_vector_insert(&update_heads, head) < 0)
1598
- goto on_error;
1599
- }
1875
+ if (!(error || error == GIT_ENOTFOUND) &&
1876
+ !spec->force &&
1877
+ !git_graph_descendant_of(remote->repo, &head->oid, &old)) {
1878
+ error = 0;
1879
+ goto done;
1880
+ }
1600
1881
 
1601
- if (!git_oid__cmp(&old, &head->oid))
1602
- continue;
1882
+ if (error == GIT_ENOTFOUND) {
1883
+ git_oid_clear(&old, remote->repo->oid_type);
1884
+ error = 0;
1603
1885
 
1886
+ if (autotag && (error = git_vector_insert(update_heads, head)) < 0)
1887
+ goto done;
1888
+ }
1889
+
1890
+ if ((updated = !git_oid_equal(&old, &head->oid))) {
1604
1891
  /* In autotag mode, don't overwrite any locally-existing tags */
1605
1892
  error = git_reference_create(&ref, remote->repo, refname.ptr, &head->oid, !autotag,
1606
1893
  log_message);
1607
1894
 
1608
- if (error == GIT_EEXISTS)
1609
- continue;
1895
+ if (error < 0) {
1896
+ if (error == GIT_EEXISTS)
1897
+ error = 0;
1610
1898
 
1611
- if (error < 0)
1899
+ goto done;
1900
+ }
1901
+ }
1902
+
1903
+ if (!callbacks ||
1904
+ (!updated && (update_flags & GIT_REMOTE_UPDATE_REPORT_UNCHANGED) == 0))
1905
+ goto done;
1906
+
1907
+ if (callbacks && callbacks->update_refs)
1908
+ error = callbacks->update_refs(refname.ptr, &old,
1909
+ &head->oid, spec, callbacks->payload);
1910
+ #ifndef GIT_DEPRECATE_HARD
1911
+ else if (callbacks && callbacks->update_tips)
1912
+ error = callbacks->update_tips(refname.ptr, &old,
1913
+ &head->oid, callbacks->payload);
1914
+ #endif
1915
+
1916
+ if (error < 0)
1917
+ git_error_set_after_callback_function(error, "git_remote_fetch");
1918
+
1919
+ done:
1920
+ git_reference_free(ref);
1921
+ git_str_dispose(&refname);
1922
+ return error;
1923
+ }
1924
+
1925
+ static int update_tips_for_spec(
1926
+ git_remote *remote,
1927
+ const git_remote_callbacks *callbacks,
1928
+ unsigned int update_flags,
1929
+ git_remote_autotag_option_t tagopt,
1930
+ git_refspec *spec,
1931
+ git_vector *refs,
1932
+ const char *log_message)
1933
+ {
1934
+ git_refspec tagspec;
1935
+ git_remote_head *head, oid_head;
1936
+ git_vector update_heads;
1937
+ int error = 0;
1938
+ size_t i;
1939
+
1940
+ GIT_ASSERT_ARG(remote && remote->repo);
1941
+
1942
+ if (git_refspec__parse(&tagspec, GIT_REFSPEC_TAGS, true) < 0)
1943
+ return -1;
1944
+
1945
+ /* Make a copy of the transport's refs */
1946
+ if (git_vector_init(&update_heads, 16, NULL) < 0)
1947
+ return -1;
1948
+
1949
+ /* Update tips based on the remote heads */
1950
+ git_vector_foreach(refs, i, head) {
1951
+ if (update_one_tip(&update_heads,
1952
+ remote, spec, head, &tagspec,
1953
+ update_flags, tagopt, log_message,
1954
+ callbacks) < 0)
1612
1955
  goto on_error;
1956
+ }
1613
1957
 
1614
- git_reference_free(ref);
1958
+ /* Handle specified oid sources */
1959
+ if (git_oid__is_hexstr(spec->src, remote->repo->oid_type)) {
1960
+ git_oid id;
1615
1961
 
1616
- if (callbacks && callbacks->update_tips != NULL) {
1617
- if (callbacks->update_tips(refname.ptr, &old, &head->oid, callbacks->payload) < 0)
1618
- goto on_error;
1619
- }
1962
+ if ((error = git_oid__fromstr(&id, spec->src, remote->repo->oid_type)) < 0)
1963
+ goto on_error;
1964
+
1965
+ if (spec->dst &&
1966
+ (error = update_ref(remote, spec->dst, &id, spec, log_message, callbacks)) < 0)
1967
+ goto on_error;
1968
+
1969
+ git_oid_cpy(&oid_head.oid, &id);
1970
+ oid_head.name = spec->src;
1971
+
1972
+ if ((error = git_vector_insert(&update_heads, &oid_head)) < 0)
1973
+ goto on_error;
1620
1974
  }
1621
1975
 
1622
- if (update_fetchhead &&
1976
+ if ((update_flags & GIT_REMOTE_UPDATE_FETCHHEAD) &&
1623
1977
  (error = git_remote_write_fetchhead(remote, spec, &update_heads)) < 0)
1624
1978
  goto on_error;
1625
1979
 
1626
- git_vector_free(&update_heads);
1627
1980
  git_refspec__dispose(&tagspec);
1628
- git_buf_dispose(&refname);
1981
+ git_vector_dispose(&update_heads);
1629
1982
  return 0;
1630
1983
 
1631
1984
  on_error:
1632
- git_vector_free(&update_heads);
1633
1985
  git_refspec__dispose(&tagspec);
1634
- git_buf_dispose(&refname);
1986
+ git_vector_dispose(&update_heads);
1635
1987
  return -1;
1636
1988
 
1637
1989
  }
@@ -1697,20 +2049,22 @@ static int next_head(const git_remote *remote, git_vector *refs,
1697
2049
  return GIT_ITEROVER;
1698
2050
  }
1699
2051
 
1700
- static int opportunistic_updates(const git_remote *remote, const git_remote_callbacks *callbacks,
1701
- git_vector *refs, const char *msg)
2052
+ static int opportunistic_updates(
2053
+ const git_remote *remote,
2054
+ const git_remote_callbacks *callbacks,
2055
+ git_vector *refs,
2056
+ const char *msg)
1702
2057
  {
1703
2058
  size_t i, j, k;
1704
2059
  git_refspec *spec;
1705
2060
  git_remote_head *head;
1706
- git_reference *ref;
1707
- git_buf refname = GIT_BUF_INIT;
2061
+ git_str refname = GIT_STR_INIT;
1708
2062
  int error = 0;
1709
2063
 
1710
2064
  i = j = k = 0;
1711
2065
 
2066
+ /* Handle refspecs matching remote heads */
1712
2067
  while ((error = next_head(remote, refs, &spec, &head, &i, &j, &k)) == 0) {
1713
- git_oid old = {{ 0 }};
1714
2068
  /*
1715
2069
  * If we got here, there is a refspec which was used
1716
2070
  * for fetching which matches the source of one of the
@@ -1719,60 +2073,42 @@ static int opportunistic_updates(const git_remote *remote, const git_remote_call
1719
2073
  * FETCH_HEAD
1720
2074
  */
1721
2075
 
1722
- git_buf_clear(&refname);
1723
- if ((error = git_refspec_transform(&refname, spec, head->name)) < 0)
1724
- goto cleanup;
1725
-
1726
- error = git_reference_name_to_id(&old, remote->repo, refname.ptr);
1727
- if (error < 0 && error != GIT_ENOTFOUND)
1728
- goto cleanup;
1729
-
1730
- if (!git_oid_cmp(&old, &head->oid))
1731
- continue;
1732
-
1733
- /* If we did find a current reference, make sure we haven't lost a race */
1734
- if (error)
1735
- error = git_reference_create(&ref, remote->repo, refname.ptr, &head->oid, true, msg);
1736
- else
1737
- error = git_reference_create_matching(&ref, remote->repo, refname.ptr, &head->oid, true, &old, msg);
1738
- git_reference_free(ref);
1739
- if (error < 0)
2076
+ git_str_clear(&refname);
2077
+ if ((error = git_refspec__transform(&refname, spec, head->name)) < 0 ||
2078
+ (error = update_ref(remote, refname.ptr, &head->oid, spec, msg, callbacks)) < 0)
1740
2079
  goto cleanup;
1741
-
1742
- if (callbacks && callbacks->update_tips != NULL) {
1743
- if (callbacks->update_tips(refname.ptr, &old, &head->oid, callbacks->payload) < 0)
1744
- goto cleanup;
1745
- }
1746
2080
  }
1747
2081
 
1748
- if (error == GIT_ITEROVER)
1749
- error = 0;
2082
+ if (error != GIT_ITEROVER)
2083
+ goto cleanup;
2084
+
2085
+ error = 0;
1750
2086
 
1751
2087
  cleanup:
1752
- git_buf_dispose(&refname);
2088
+ git_str_dispose(&refname);
1753
2089
  return error;
1754
2090
  }
1755
2091
 
1756
2092
  static int truncate_fetch_head(const char *gitdir)
1757
2093
  {
1758
- git_buf path = GIT_BUF_INIT;
2094
+ git_str path = GIT_STR_INIT;
1759
2095
  int error;
1760
2096
 
1761
- if ((error = git_buf_joinpath(&path, gitdir, GIT_FETCH_HEAD_FILE)) < 0)
2097
+ if ((error = git_str_joinpath(&path, gitdir, GIT_FETCH_HEAD_FILE)) < 0)
1762
2098
  return error;
1763
2099
 
1764
2100
  error = git_futils_truncate(path.ptr, GIT_REFS_FILE_MODE);
1765
- git_buf_dispose(&path);
2101
+ git_str_dispose(&path);
1766
2102
 
1767
2103
  return error;
1768
2104
  }
1769
2105
 
1770
2106
  int git_remote_update_tips(
1771
- git_remote *remote,
1772
- const git_remote_callbacks *callbacks,
1773
- int update_fetchhead,
1774
- git_remote_autotag_option_t download_tags,
1775
- const char *reflog_message)
2107
+ git_remote *remote,
2108
+ const git_remote_callbacks *callbacks,
2109
+ unsigned int update_flags,
2110
+ git_remote_autotag_option_t download_tags,
2111
+ const char *reflog_message)
1776
2112
  {
1777
2113
  git_refspec *spec, tagspec;
1778
2114
  git_vector refs = GIT_VECTOR_INIT;
@@ -1801,7 +2137,7 @@ int git_remote_update_tips(
1801
2137
  goto out;
1802
2138
 
1803
2139
  if (tagopt == GIT_REMOTE_DOWNLOAD_TAGS_ALL) {
1804
- if ((error = update_tips_for_spec(remote, callbacks, update_fetchhead, tagopt, &tagspec, &refs, reflog_message)) < 0)
2140
+ if ((error = update_tips_for_spec(remote, callbacks, update_flags, tagopt, &tagspec, &refs, reflog_message)) < 0)
1805
2141
  goto out;
1806
2142
  }
1807
2143
 
@@ -1809,16 +2145,16 @@ int git_remote_update_tips(
1809
2145
  if (spec->push)
1810
2146
  continue;
1811
2147
 
1812
- if ((error = update_tips_for_spec(remote, callbacks, update_fetchhead, tagopt, spec, &refs, reflog_message)) < 0)
2148
+ if ((error = update_tips_for_spec(remote, callbacks, update_flags, tagopt, spec, &refs, reflog_message)) < 0)
1813
2149
  goto out;
1814
2150
  }
1815
2151
 
1816
- /* Only try to do opportunistic updates if the refpec lists differ. */
2152
+ /* Only try to do opportunistic updates if the refspec lists differ. */
1817
2153
  if (remote->passed_refspecs)
1818
2154
  error = opportunistic_updates(remote, callbacks, &refs, reflog_message);
1819
2155
 
1820
2156
  out:
1821
- git_vector_free(&refs);
2157
+ git_vector_dispose(&refs);
1822
2158
  git_refspec__dispose(&tagspec);
1823
2159
  return error;
1824
2160
  }
@@ -1854,6 +2190,17 @@ int git_remote_disconnect(git_remote *remote)
1854
2190
  return 0;
1855
2191
  }
1856
2192
 
2193
+ static void free_heads(git_vector *heads)
2194
+ {
2195
+ git_remote_head *head;
2196
+ size_t i;
2197
+
2198
+ git_vector_foreach(heads, i, head) {
2199
+ git__free(head->name);
2200
+ git__free(head);
2201
+ }
2202
+ }
2203
+
1857
2204
  void git_remote_free(git_remote *remote)
1858
2205
  {
1859
2206
  if (remote == NULL)
@@ -1866,16 +2213,19 @@ void git_remote_free(git_remote *remote)
1866
2213
  remote->transport = NULL;
1867
2214
  }
1868
2215
 
1869
- git_vector_free(&remote->refs);
2216
+ git_vector_dispose(&remote->refs);
1870
2217
 
1871
2218
  free_refspecs(&remote->refspecs);
1872
- git_vector_free(&remote->refspecs);
2219
+ git_vector_dispose(&remote->refspecs);
1873
2220
 
1874
2221
  free_refspecs(&remote->active_refspecs);
1875
- git_vector_free(&remote->active_refspecs);
2222
+ git_vector_dispose(&remote->active_refspecs);
1876
2223
 
1877
2224
  free_refspecs(&remote->passive_refspecs);
1878
- git_vector_free(&remote->passive_refspecs);
2225
+ git_vector_dispose(&remote->passive_refspecs);
2226
+
2227
+ free_heads(&remote->local_heads);
2228
+ git_vector_dispose(&remote->local_heads);
1879
2229
 
1880
2230
  git_push_free(remote->push);
1881
2231
  git__free(remote->url);
@@ -1918,7 +2268,7 @@ int git_remote_list(git_strarray *remotes_list, git_repository *repo)
1918
2268
  cfg, "^remote\\..*\\.(push)?url$", remote_list_cb, &list);
1919
2269
 
1920
2270
  if (error < 0) {
1921
- git_vector_free_deep(&list);
2271
+ git_vector_dispose_deep(&list);
1922
2272
  return error;
1923
2273
  }
1924
2274
 
@@ -1943,7 +2293,7 @@ git_remote_autotag_option_t git_remote_autotag(const git_remote *remote)
1943
2293
 
1944
2294
  int git_remote_set_autotag(git_repository *repo, const char *remote, git_remote_autotag_option_t value)
1945
2295
  {
1946
- git_buf var = GIT_BUF_INIT;
2296
+ git_str var = GIT_STR_INIT;
1947
2297
  git_config *config;
1948
2298
  int error;
1949
2299
 
@@ -1955,7 +2305,7 @@ int git_remote_set_autotag(git_repository *repo, const char *remote, git_remote_
1955
2305
  if ((error = git_repository_config__weakptr(&config, repo)) < 0)
1956
2306
  return error;
1957
2307
 
1958
- if ((error = git_buf_printf(&var, CONFIG_TAGOPT_FMT, remote)))
2308
+ if ((error = git_str_printf(&var, CONFIG_TAGOPT_FMT, remote)))
1959
2309
  return error;
1960
2310
 
1961
2311
  switch (value) {
@@ -1975,7 +2325,7 @@ int git_remote_set_autotag(git_repository *repo, const char *remote, git_remote_
1975
2325
  error = -1;
1976
2326
  }
1977
2327
 
1978
- git_buf_dispose(&var);
2328
+ git_str_dispose(&var);
1979
2329
  return error;
1980
2330
  }
1981
2331
 
@@ -1989,25 +2339,25 @@ static int rename_remote_config_section(
1989
2339
  const char *old_name,
1990
2340
  const char *new_name)
1991
2341
  {
1992
- git_buf old_section_name = GIT_BUF_INIT,
1993
- new_section_name = GIT_BUF_INIT;
2342
+ git_str old_section_name = GIT_STR_INIT,
2343
+ new_section_name = GIT_STR_INIT;
1994
2344
  int error = -1;
1995
2345
 
1996
- if (git_buf_printf(&old_section_name, "remote.%s", old_name) < 0)
2346
+ if (git_str_printf(&old_section_name, "remote.%s", old_name) < 0)
1997
2347
  goto cleanup;
1998
2348
 
1999
2349
  if (new_name &&
2000
- (git_buf_printf(&new_section_name, "remote.%s", new_name) < 0))
2350
+ (git_str_printf(&new_section_name, "remote.%s", new_name) < 0))
2001
2351
  goto cleanup;
2002
2352
 
2003
2353
  error = git_config_rename_section(
2004
2354
  repo,
2005
- git_buf_cstr(&old_section_name),
2006
- new_name ? git_buf_cstr(&new_section_name) : NULL);
2355
+ git_str_cstr(&old_section_name),
2356
+ new_name ? git_str_cstr(&new_section_name) : NULL);
2007
2357
 
2008
2358
  cleanup:
2009
- git_buf_dispose(&old_section_name);
2010
- git_buf_dispose(&new_section_name);
2359
+ git_str_dispose(&old_section_name);
2360
+ git_str_dispose(&new_section_name);
2011
2361
 
2012
2362
  return error;
2013
2363
  }
@@ -2056,27 +2406,27 @@ static int rename_one_remote_reference(
2056
2406
  {
2057
2407
  int error;
2058
2408
  git_reference *ref = NULL, *dummy = NULL;
2059
- git_buf namespace = GIT_BUF_INIT, old_namespace = GIT_BUF_INIT;
2060
- git_buf new_name = GIT_BUF_INIT;
2061
- git_buf log_message = GIT_BUF_INIT;
2409
+ git_str namespace = GIT_STR_INIT, old_namespace = GIT_STR_INIT;
2410
+ git_str new_name = GIT_STR_INIT;
2411
+ git_str log_message = GIT_STR_INIT;
2062
2412
  size_t pfx_len;
2063
2413
  const char *target;
2064
2414
 
2065
- if ((error = git_buf_printf(&namespace, GIT_REFS_REMOTES_DIR "%s/", new_remote_name)) < 0)
2415
+ if ((error = git_str_printf(&namespace, GIT_REFS_REMOTES_DIR "%s/", new_remote_name)) < 0)
2066
2416
  return error;
2067
2417
 
2068
2418
  pfx_len = strlen(GIT_REFS_REMOTES_DIR) + strlen(old_remote_name) + 1;
2069
- git_buf_puts(&new_name, namespace.ptr);
2070
- if ((error = git_buf_puts(&new_name, git_reference_name(reference_in) + pfx_len)) < 0)
2419
+ git_str_puts(&new_name, namespace.ptr);
2420
+ if ((error = git_str_puts(&new_name, git_reference_name(reference_in) + pfx_len)) < 0)
2071
2421
  goto cleanup;
2072
2422
 
2073
- if ((error = git_buf_printf(&log_message,
2423
+ if ((error = git_str_printf(&log_message,
2074
2424
  "renamed remote %s to %s",
2075
2425
  old_remote_name, new_remote_name)) < 0)
2076
2426
  goto cleanup;
2077
2427
 
2078
- if ((error = git_reference_rename(&ref, reference_in, git_buf_cstr(&new_name), 1,
2079
- git_buf_cstr(&log_message))) < 0)
2428
+ if ((error = git_reference_rename(&ref, reference_in, git_str_cstr(&new_name), 1,
2429
+ git_str_cstr(&log_message))) < 0)
2080
2430
  goto cleanup;
2081
2431
 
2082
2432
  if (git_reference_type(ref) != GIT_REFERENCE_SYMBOLIC)
@@ -2084,29 +2434,29 @@ static int rename_one_remote_reference(
2084
2434
 
2085
2435
  /* Handle refs like origin/HEAD -> origin/master */
2086
2436
  target = git_reference_symbolic_target(ref);
2087
- if ((error = git_buf_printf(&old_namespace, GIT_REFS_REMOTES_DIR "%s/", old_remote_name)) < 0)
2437
+ if ((error = git_str_printf(&old_namespace, GIT_REFS_REMOTES_DIR "%s/", old_remote_name)) < 0)
2088
2438
  goto cleanup;
2089
2439
 
2090
2440
  if (git__prefixcmp(target, old_namespace.ptr))
2091
2441
  goto cleanup;
2092
2442
 
2093
- git_buf_clear(&new_name);
2094
- git_buf_puts(&new_name, namespace.ptr);
2095
- if ((error = git_buf_puts(&new_name, target + pfx_len)) < 0)
2443
+ git_str_clear(&new_name);
2444
+ git_str_puts(&new_name, namespace.ptr);
2445
+ if ((error = git_str_puts(&new_name, target + pfx_len)) < 0)
2096
2446
  goto cleanup;
2097
2447
 
2098
- error = git_reference_symbolic_set_target(&dummy, ref, git_buf_cstr(&new_name),
2099
- git_buf_cstr(&log_message));
2448
+ error = git_reference_symbolic_set_target(&dummy, ref, git_str_cstr(&new_name),
2449
+ git_str_cstr(&log_message));
2100
2450
 
2101
2451
  git_reference_free(dummy);
2102
2452
 
2103
2453
  cleanup:
2104
2454
  git_reference_free(reference_in);
2105
2455
  git_reference_free(ref);
2106
- git_buf_dispose(&namespace);
2107
- git_buf_dispose(&old_namespace);
2108
- git_buf_dispose(&new_name);
2109
- git_buf_dispose(&log_message);
2456
+ git_str_dispose(&namespace);
2457
+ git_str_dispose(&old_namespace);
2458
+ git_str_dispose(&new_name);
2459
+ git_str_dispose(&log_message);
2110
2460
  return error;
2111
2461
  }
2112
2462
 
@@ -2116,15 +2466,15 @@ static int rename_remote_references(
2116
2466
  const char *new_name)
2117
2467
  {
2118
2468
  int error;
2119
- git_buf buf = GIT_BUF_INIT;
2469
+ git_str buf = GIT_STR_INIT;
2120
2470
  git_reference *ref;
2121
2471
  git_reference_iterator *iter;
2122
2472
 
2123
- if ((error = git_buf_printf(&buf, GIT_REFS_REMOTES_DIR "%s/*", old_name)) < 0)
2473
+ if ((error = git_str_printf(&buf, GIT_REFS_REMOTES_DIR "%s/*", old_name)) < 0)
2124
2474
  return error;
2125
2475
 
2126
- error = git_reference_iterator_glob_new(&iter, repo, git_buf_cstr(&buf));
2127
- git_buf_dispose(&buf);
2476
+ error = git_reference_iterator_glob_new(&iter, repo, git_str_cstr(&buf));
2477
+ git_str_dispose(&buf);
2128
2478
 
2129
2479
  if (error < 0)
2130
2480
  return error;
@@ -2142,7 +2492,7 @@ static int rename_remote_references(
2142
2492
  static int rename_fetch_refspecs(git_vector *problems, git_remote *remote, const char *new_name)
2143
2493
  {
2144
2494
  git_config *config;
2145
- git_buf base = GIT_BUF_INIT, var = GIT_BUF_INIT, val = GIT_BUF_INIT;
2495
+ git_str base = GIT_STR_INIT, var = GIT_STR_INIT, val = GIT_STR_INIT;
2146
2496
  const git_refspec *spec;
2147
2497
  size_t i;
2148
2498
  int error = 0;
@@ -2161,7 +2511,7 @@ static int rename_fetch_refspecs(git_vector *problems, git_remote *remote, const
2161
2511
  continue;
2162
2512
 
2163
2513
  /* Does the dst part of the refspec follow the expected format? */
2164
- if (strcmp(git_buf_cstr(&base), spec->string)) {
2514
+ if (strcmp(git_str_cstr(&base), spec->string)) {
2165
2515
  char *dup;
2166
2516
 
2167
2517
  dup = git__strdup(spec->string);
@@ -2175,31 +2525,31 @@ static int rename_fetch_refspecs(git_vector *problems, git_remote *remote, const
2175
2525
 
2176
2526
  /* If we do want to move it to the new section */
2177
2527
 
2178
- git_buf_clear(&val);
2179
- git_buf_clear(&var);
2528
+ git_str_clear(&val);
2529
+ git_str_clear(&var);
2180
2530
 
2181
2531
  if (default_fetchspec_for_name(&val, new_name) < 0 ||
2182
- git_buf_printf(&var, "remote.%s.fetch", new_name) < 0)
2532
+ git_str_printf(&var, "remote.%s.fetch", new_name) < 0)
2183
2533
  {
2184
2534
  error = -1;
2185
2535
  break;
2186
2536
  }
2187
2537
 
2188
2538
  if ((error = git_config_set_string(
2189
- config, git_buf_cstr(&var), git_buf_cstr(&val))) < 0)
2539
+ config, git_str_cstr(&var), git_str_cstr(&val))) < 0)
2190
2540
  break;
2191
2541
  }
2192
2542
 
2193
- git_buf_dispose(&base);
2194
- git_buf_dispose(&var);
2195
- git_buf_dispose(&val);
2543
+ git_str_dispose(&base);
2544
+ git_str_dispose(&var);
2545
+ git_str_dispose(&val);
2196
2546
 
2197
2547
  if (error < 0) {
2198
2548
  char *str;
2199
2549
  git_vector_foreach(problems, i, str)
2200
2550
  git__free(str);
2201
2551
 
2202
- git_vector_free(problems);
2552
+ git_vector_dispose(problems);
2203
2553
  }
2204
2554
 
2205
2555
  return error;
@@ -2239,7 +2589,7 @@ int git_remote_rename(git_strarray *out, git_repository *repo, const char *name,
2239
2589
 
2240
2590
  cleanup:
2241
2591
  if (error < 0)
2242
- git_vector_free(&problem_refspecs);
2592
+ git_vector_dispose(&problem_refspecs);
2243
2593
 
2244
2594
  git_remote_free(remote);
2245
2595
  return error;
@@ -2247,7 +2597,7 @@ cleanup:
2247
2597
 
2248
2598
  int git_remote_name_is_valid(int *valid, const char *remote_name)
2249
2599
  {
2250
- git_buf buf = GIT_BUF_INIT;
2600
+ git_str buf = GIT_STR_INIT;
2251
2601
  git_refspec refspec = {0};
2252
2602
  int error;
2253
2603
 
@@ -2258,10 +2608,10 @@ int git_remote_name_is_valid(int *valid, const char *remote_name)
2258
2608
  if (!remote_name || *remote_name == '\0')
2259
2609
  return 0;
2260
2610
 
2261
- if ((error = git_buf_printf(&buf, "refs/heads/test:refs/remotes/%s/test", remote_name)) < 0)
2611
+ if ((error = git_str_printf(&buf, "refs/heads/test:refs/remotes/%s/test", remote_name)) < 0)
2262
2612
  goto done;
2263
2613
 
2264
- error = git_refspec__parse(&refspec, git_buf_cstr(&buf), true);
2614
+ error = git_refspec__parse(&refspec, git_str_cstr(&buf), true);
2265
2615
 
2266
2616
  if (!error)
2267
2617
  *valid = 1;
@@ -2269,7 +2619,7 @@ int git_remote_name_is_valid(int *valid, const char *remote_name)
2269
2619
  error = 0;
2270
2620
 
2271
2621
  done:
2272
- git_buf_dispose(&buf);
2622
+ git_str_dispose(&buf);
2273
2623
  git_refspec__dispose(&refspec);
2274
2624
 
2275
2625
  return error;
@@ -2278,17 +2628,21 @@ done:
2278
2628
  git_refspec *git_remote__matching_refspec(git_remote *remote, const char *refname)
2279
2629
  {
2280
2630
  git_refspec *spec;
2631
+ git_refspec *match = NULL;
2281
2632
  size_t i;
2282
2633
 
2283
2634
  git_vector_foreach(&remote->active_refspecs, i, spec) {
2284
2635
  if (spec->push)
2285
2636
  continue;
2286
2637
 
2287
- if (git_refspec_src_matches(spec, refname))
2288
- return spec;
2638
+ if (git_refspec_src_matches_negative(spec, refname))
2639
+ return NULL;
2640
+
2641
+ if (git_refspec_src_matches(spec, refname) && match == NULL)
2642
+ match = spec;
2289
2643
  }
2290
2644
 
2291
- return NULL;
2645
+ return match;
2292
2646
  }
2293
2647
 
2294
2648
  git_refspec *git_remote__matching_dst_refspec(git_remote *remote, const char *refname)
@@ -2346,7 +2700,7 @@ static int copy_refspecs(git_strarray *array, const git_remote *remote, unsigned
2346
2700
  return 0;
2347
2701
 
2348
2702
  on_error:
2349
- git_vector_free_deep(&refspecs);
2703
+ git_vector_dispose_deep(&refspecs);
2350
2704
 
2351
2705
  return -1;
2352
2706
  }
@@ -2401,7 +2755,7 @@ static int remove_branch_config_related_entries(
2401
2755
  git_config *config;
2402
2756
  git_config_entry *entry;
2403
2757
  git_config_iterator *iter;
2404
- git_buf buf = GIT_BUF_INIT;
2758
+ git_str buf = GIT_STR_INIT;
2405
2759
 
2406
2760
  if ((error = git_repository_config__weakptr(&config, repo)) < 0)
2407
2761
  return error;
@@ -2422,21 +2776,21 @@ static int remove_branch_config_related_entries(
2422
2776
  break;
2423
2777
  }
2424
2778
 
2425
- git_buf_clear(&buf);
2426
- if ((error = git_buf_printf(&buf, "branch.%.*s.merge", (int)branch_len, branch)) < 0)
2779
+ git_str_clear(&buf);
2780
+ if ((error = git_str_printf(&buf, "branch.%.*s.merge", (int)branch_len, branch)) < 0)
2427
2781
  break;
2428
2782
 
2429
- if ((error = git_config_delete_entry(config, git_buf_cstr(&buf))) < 0) {
2783
+ if ((error = git_config_delete_entry(config, git_str_cstr(&buf))) < 0) {
2430
2784
  if (error != GIT_ENOTFOUND)
2431
2785
  break;
2432
2786
  git_error_clear();
2433
2787
  }
2434
2788
 
2435
- git_buf_clear(&buf);
2436
- if ((error = git_buf_printf(&buf, "branch.%.*s.remote", (int)branch_len, branch)) < 0)
2789
+ git_str_clear(&buf);
2790
+ if ((error = git_str_printf(&buf, "branch.%.*s.remote", (int)branch_len, branch)) < 0)
2437
2791
  break;
2438
2792
 
2439
- if ((error = git_config_delete_entry(config, git_buf_cstr(&buf))) < 0) {
2793
+ if ((error = git_config_delete_entry(config, git_str_cstr(&buf))) < 0) {
2440
2794
  if (error != GIT_ENOTFOUND)
2441
2795
  break;
2442
2796
  git_error_clear();
@@ -2446,7 +2800,7 @@ static int remove_branch_config_related_entries(
2446
2800
  if (error == GIT_ITEROVER)
2447
2801
  error = 0;
2448
2802
 
2449
- git_buf_dispose(&buf);
2803
+ git_str_dispose(&buf);
2450
2804
  git_config_iterator_free(iter);
2451
2805
  return error;
2452
2806
  }
@@ -2494,7 +2848,7 @@ cleanup:
2494
2848
  git_vector_foreach(&refs, i, dup) {
2495
2849
  git__free(dup);
2496
2850
  }
2497
- git_vector_free(&refs);
2851
+ git_vector_dispose(&refs);
2498
2852
  return error;
2499
2853
  }
2500
2854
 
@@ -2540,12 +2894,17 @@ int git_remote_delete(git_repository *repo, const char *name)
2540
2894
  }
2541
2895
 
2542
2896
  int git_remote_default_branch(git_buf *out, git_remote *remote)
2897
+ {
2898
+ GIT_BUF_WRAP_PRIVATE(out, git_remote__default_branch, remote);
2899
+ }
2900
+
2901
+ int git_remote__default_branch(git_str *out, git_remote *remote)
2543
2902
  {
2544
2903
  const git_remote_head **heads;
2545
2904
  const git_remote_head *guess = NULL;
2546
2905
  const git_oid *head_id;
2547
2906
  size_t heads_len, i;
2548
- git_buf local_default = GIT_BUF_INIT;
2907
+ git_str local_default = GIT_STR_INIT;
2549
2908
  int error;
2550
2909
 
2551
2910
  GIT_ASSERT_ARG(out);
@@ -2558,12 +2917,9 @@ int git_remote_default_branch(git_buf *out, git_remote *remote)
2558
2917
  goto done;
2559
2918
  }
2560
2919
 
2561
- if ((error = git_buf_sanitize(out)) < 0)
2562
- return error;
2563
-
2564
2920
  /* the first one must be HEAD so if that has the symref info, we're done */
2565
2921
  if (heads[0]->symref_target) {
2566
- error = git_buf_puts(out, heads[0]->symref_target);
2922
+ error = git_str_puts(out, heads[0]->symref_target);
2567
2923
  goto done;
2568
2924
  }
2569
2925
 
@@ -2601,21 +2957,23 @@ int git_remote_default_branch(git_buf *out, git_remote *remote)
2601
2957
  goto done;
2602
2958
  }
2603
2959
 
2604
- error = git_buf_puts(out, guess->name);
2960
+ error = git_str_puts(out, guess->name);
2605
2961
 
2606
2962
  done:
2607
- git_buf_dispose(&local_default);
2963
+ git_str_dispose(&local_default);
2608
2964
  return error;
2609
2965
  }
2610
2966
 
2611
- int git_remote_upload(git_remote *remote, const git_strarray *refspecs, const git_push_options *opts)
2967
+ int git_remote_upload(
2968
+ git_remote *remote,
2969
+ const git_strarray *refspecs,
2970
+ const git_push_options *opts)
2612
2971
  {
2613
- size_t i;
2614
- int error;
2972
+ git_remote_connect_options connect_opts = GIT_REMOTE_CONNECT_OPTIONS_INIT;
2615
2973
  git_push *push;
2616
2974
  git_refspec *spec;
2617
- const git_remote_callbacks *cbs = NULL;
2618
- git_remote_connection_opts conn = GIT_REMOTE_CONNECTION_OPTIONS_INIT;
2975
+ size_t i;
2976
+ int error;
2619
2977
 
2620
2978
  GIT_ASSERT_ARG(remote);
2621
2979
 
@@ -2624,14 +2982,11 @@ int git_remote_upload(git_remote *remote, const git_strarray *refspecs, const gi
2624
2982
  return -1;
2625
2983
  }
2626
2984
 
2627
- if (opts) {
2628
- cbs = &opts->callbacks;
2629
- conn.custom_headers = &opts->custom_headers;
2630
- conn.proxy = &opts->proxy_opts;
2631
- }
2985
+ if ((error = git_remote_connect_options__from_push_opts(
2986
+ &connect_opts, remote, opts)) < 0)
2987
+ goto cleanup;
2632
2988
 
2633
- if (!git_remote_connected(remote) &&
2634
- (error = git_remote__connect(remote, GIT_DIRECTION_PUSH, cbs, &conn)) < 0)
2989
+ if ((error = connect_or_reset_options(remote, GIT_DIRECTION_PUSH, &connect_opts)) < 0)
2635
2990
  goto cleanup;
2636
2991
 
2637
2992
  free_refspecs(&remote->active_refspecs);
@@ -2643,14 +2998,11 @@ int git_remote_upload(git_remote *remote, const git_strarray *refspecs, const gi
2643
2998
  remote->push = NULL;
2644
2999
  }
2645
3000
 
2646
- if ((error = git_push_new(&remote->push, remote)) < 0)
2647
- return error;
3001
+ if ((error = git_push_new(&remote->push, remote, opts)) < 0)
3002
+ goto cleanup;
2648
3003
 
2649
3004
  push = remote->push;
2650
3005
 
2651
- if (opts && (error = git_push_set_options(push, opts)) < 0)
2652
- goto cleanup;
2653
-
2654
3006
  if (refspecs && refspecs->count > 0) {
2655
3007
  for (i = 0; i < refspecs->count; i++) {
2656
3008
  if ((error = git_push_add_refspec(push, refspecs->strings[i])) < 0)
@@ -2665,23 +3017,35 @@ int git_remote_upload(git_remote *remote, const git_strarray *refspecs, const gi
2665
3017
  }
2666
3018
  }
2667
3019
 
2668
- if ((error = git_push_finish(push, cbs)) < 0)
2669
- goto cleanup;
3020
+ if (opts && opts->remote_push_options.count > 0)
3021
+ for (i = 0; i < opts->remote_push_options.count; ++i) {
3022
+ char *optstr = git__strdup(opts->remote_push_options.strings[i]);
3023
+ GIT_ERROR_CHECK_ALLOC(optstr);
2670
3024
 
2671
- if (cbs && cbs->push_update_reference &&
2672
- (error = git_push_status_foreach(push, cbs->push_update_reference, cbs->payload)) < 0)
2673
- goto cleanup;
3025
+ if ((error = git_vector_insert(&push->remote_push_options, optstr)) < 0)
3026
+ goto cleanup;
3027
+ }
3028
+
3029
+ error = git_push_finish(push);
3030
+
3031
+ if (connect_opts.callbacks.push_update_reference) {
3032
+ const int cb_error = git_push_status_foreach(push, connect_opts.callbacks.push_update_reference, connect_opts.callbacks.payload);
3033
+ if (!error)
3034
+ error = cb_error;
3035
+ }
2674
3036
 
2675
3037
  cleanup:
3038
+ git_remote_connect_options_dispose(&connect_opts);
2676
3039
  return error;
2677
3040
  }
2678
3041
 
2679
- int git_remote_push(git_remote *remote, const git_strarray *refspecs, const git_push_options *opts)
3042
+ int git_remote_push(
3043
+ git_remote *remote,
3044
+ const git_strarray *refspecs,
3045
+ const git_push_options *opts)
2680
3046
  {
3047
+ git_remote_connect_options connect_opts = GIT_REMOTE_CONNECT_OPTIONS_INIT;
2681
3048
  int error;
2682
- const git_remote_callbacks *cbs = NULL;
2683
- const git_strarray *custom_headers = NULL;
2684
- const git_proxy_options *proxy = NULL;
2685
3049
 
2686
3050
  GIT_ASSERT_ARG(remote);
2687
3051
 
@@ -2690,23 +3054,18 @@ int git_remote_push(git_remote *remote, const git_strarray *refspecs, const git_
2690
3054
  return -1;
2691
3055
  }
2692
3056
 
2693
- if (opts) {
2694
- GIT_ERROR_CHECK_VERSION(&opts->callbacks, GIT_REMOTE_CALLBACKS_VERSION, "git_remote_callbacks");
2695
- cbs = &opts->callbacks;
2696
- custom_headers = &opts->custom_headers;
2697
- GIT_ERROR_CHECK_VERSION(&opts->proxy_opts, GIT_PROXY_OPTIONS_VERSION, "git_proxy_options");
2698
- proxy = &opts->proxy_opts;
2699
- }
2700
-
2701
- if ((error = git_remote_connect(remote, GIT_DIRECTION_PUSH, cbs, proxy, custom_headers)) < 0)
2702
- return error;
3057
+ if (git_remote_connect_options__from_push_opts(&connect_opts,
3058
+ remote, opts) < 0)
3059
+ return -1;
2703
3060
 
2704
3061
  if ((error = git_remote_upload(remote, refspecs, opts)) < 0)
2705
- return error;
3062
+ goto done;
2706
3063
 
2707
- error = git_remote_update_tips(remote, cbs, 0, 0, NULL);
3064
+ error = git_remote_update_tips(remote, &connect_opts.callbacks, 0, 0, NULL);
2708
3065
 
3066
+ done:
2709
3067
  git_remote_disconnect(remote);
3068
+ git_remote_connect_options_dispose(&connect_opts);
2710
3069
  return error;
2711
3070
  }
2712
3071
 
@@ -2714,19 +3073,20 @@ int git_remote_push(git_remote *remote, const git_strarray *refspecs, const git_
2714
3073
  #define SUFFIX_FETCH "insteadof"
2715
3074
  #define SUFFIX_PUSH "pushinsteadof"
2716
3075
 
2717
- char *apply_insteadof(git_config *config, const char *url, int direction)
3076
+ static int apply_insteadof(char **out, git_config *config, const char *url, int direction, bool use_default_if_empty)
2718
3077
  {
2719
3078
  size_t match_length, prefix_length, suffix_length;
2720
3079
  char *replacement = NULL;
2721
3080
  const char *regexp;
2722
3081
 
2723
- git_buf result = GIT_BUF_INIT;
3082
+ git_str result = GIT_STR_INIT;
2724
3083
  git_config_entry *entry;
2725
3084
  git_config_iterator *iter;
2726
3085
 
2727
- GIT_ASSERT_ARG_WITH_RETVAL(config, NULL);
2728
- GIT_ASSERT_ARG_WITH_RETVAL(url, NULL);
2729
- GIT_ASSERT_ARG_WITH_RETVAL(direction == GIT_DIRECTION_FETCH || direction == GIT_DIRECTION_PUSH, NULL);
3086
+ GIT_ASSERT_ARG(out);
3087
+ GIT_ASSERT_ARG(config);
3088
+ GIT_ASSERT_ARG(url);
3089
+ GIT_ASSERT_ARG(direction == GIT_DIRECTION_FETCH || direction == GIT_DIRECTION_PUSH);
2730
3090
 
2731
3091
  /* Add 1 to prefix/suffix length due to the additional escaped dot */
2732
3092
  prefix_length = strlen(PREFIX) + 1;
@@ -2739,7 +3099,7 @@ char *apply_insteadof(git_config *config, const char *url, int direction)
2739
3099
  }
2740
3100
 
2741
3101
  if (git_config_iterator_glob_new(&iter, config, regexp) < 0)
2742
- return NULL;
3102
+ return -1;
2743
3103
 
2744
3104
  match_length = 0;
2745
3105
  while (git_config_next(&entry, iter) == 0) {
@@ -2748,6 +3108,7 @@ char *apply_insteadof(git_config *config, const char *url, int direction)
2748
3108
  /* Check if entry value is a prefix of URL */
2749
3109
  if (git__prefixcmp(url, entry->value))
2750
3110
  continue;
3111
+
2751
3112
  /* Check if entry value is longer than previous
2752
3113
  * prefixes */
2753
3114
  if ((n = strlen(entry->value)) <= match_length)
@@ -2765,14 +3126,20 @@ char *apply_insteadof(git_config *config, const char *url, int direction)
2765
3126
 
2766
3127
  git_config_iterator_free(iter);
2767
3128
 
2768
- if (match_length == 0)
2769
- return git__strdup(url);
3129
+ if (match_length == 0 && use_default_if_empty) {
3130
+ *out = git__strdup(url);
3131
+ return *out ? 0 : -1;
3132
+ } else if (match_length == 0) {
3133
+ *out = NULL;
3134
+ return 0;
3135
+ }
2770
3136
 
2771
- git_buf_printf(&result, "%s%s", replacement, url + match_length);
3137
+ git_str_printf(&result, "%s%s", replacement, url + match_length);
2772
3138
 
2773
3139
  git__free(replacement);
2774
3140
 
2775
- return result.ptr;
3141
+ *out = git_str_detach(&result);
3142
+ return 0;
2776
3143
  }
2777
3144
 
2778
3145
  /* Deprecated functions */