rugged 0.28.5 → 0.99.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (379) hide show
  1. checksums.yaml +4 -4
  2. data/ext/rugged/extconf.rb +3 -1
  3. data/ext/rugged/rugged.c +35 -31
  4. data/ext/rugged/rugged.h +13 -0
  5. data/ext/rugged/rugged_blob.c +11 -9
  6. data/ext/rugged/rugged_commit.c +17 -15
  7. data/ext/rugged/rugged_diff.c +4 -26
  8. data/ext/rugged/rugged_index.c +4 -2
  9. data/ext/rugged/rugged_note.c +5 -3
  10. data/ext/rugged/rugged_object.c +57 -10
  11. data/ext/rugged/rugged_rebase.c +3 -1
  12. data/ext/rugged/rugged_remote.c +0 -6
  13. data/ext/rugged/rugged_repo.c +222 -17
  14. data/ext/rugged/rugged_tag.c +8 -6
  15. data/ext/rugged/rugged_tree.c +18 -16
  16. data/lib/rugged/version.rb +1 -1
  17. data/vendor/libgit2/CMakeLists.txt +38 -19
  18. data/vendor/libgit2/COPYING +28 -0
  19. data/vendor/libgit2/cmake/Modules/EnableWarnings.cmake +5 -1
  20. data/vendor/libgit2/cmake/Modules/FindCoreFoundation.cmake +2 -2
  21. data/vendor/libgit2/cmake/Modules/FindGSSAPI.cmake +1 -1
  22. data/vendor/libgit2/cmake/Modules/FindGSSFramework.cmake +28 -0
  23. data/vendor/libgit2/cmake/Modules/FindPCRE.cmake +38 -0
  24. data/vendor/libgit2/cmake/Modules/FindPCRE2.cmake +37 -0
  25. data/vendor/libgit2/cmake/Modules/FindSecurity.cmake +2 -2
  26. data/vendor/libgit2/cmake/Modules/FindStatNsec.cmake +6 -0
  27. data/vendor/libgit2/cmake/Modules/PkgBuildConfig.cmake +110 -0
  28. data/vendor/libgit2/cmake/Modules/SelectGSSAPI.cmake +53 -0
  29. data/vendor/libgit2/cmake/Modules/SelectHTTPSBackend.cmake +124 -0
  30. data/vendor/libgit2/cmake/Modules/SelectHashes.cmake +66 -0
  31. data/vendor/libgit2/deps/http-parser/http_parser.c +11 -6
  32. data/vendor/libgit2/deps/ntlmclient/CMakeLists.txt +21 -0
  33. data/vendor/libgit2/deps/ntlmclient/compat.h +33 -0
  34. data/vendor/libgit2/deps/ntlmclient/crypt.h +64 -0
  35. data/vendor/libgit2/deps/ntlmclient/crypt_commoncrypto.c +120 -0
  36. data/vendor/libgit2/deps/ntlmclient/crypt_commoncrypto.h +18 -0
  37. data/vendor/libgit2/deps/ntlmclient/crypt_mbedtls.c +145 -0
  38. data/vendor/libgit2/deps/ntlmclient/crypt_mbedtls.h +18 -0
  39. data/vendor/libgit2/deps/ntlmclient/crypt_openssl.c +130 -0
  40. data/vendor/libgit2/deps/ntlmclient/crypt_openssl.h +21 -0
  41. data/vendor/libgit2/deps/ntlmclient/ntlm.c +1422 -0
  42. data/vendor/libgit2/deps/ntlmclient/ntlm.h +174 -0
  43. data/vendor/libgit2/deps/ntlmclient/ntlmclient.h +320 -0
  44. data/vendor/libgit2/deps/ntlmclient/unicode.h +36 -0
  45. data/vendor/libgit2/deps/ntlmclient/unicode_builtin.c +445 -0
  46. data/vendor/libgit2/deps/ntlmclient/unicode_iconv.c +201 -0
  47. data/vendor/libgit2/deps/ntlmclient/utf8.h +1257 -0
  48. data/vendor/libgit2/deps/ntlmclient/util.c +21 -0
  49. data/vendor/libgit2/deps/ntlmclient/util.h +14 -0
  50. data/vendor/libgit2/deps/pcre/CMakeLists.txt +140 -0
  51. data/vendor/libgit2/deps/pcre/COPYING +5 -0
  52. data/vendor/libgit2/deps/pcre/cmake/COPYING-CMAKE-SCRIPTS +22 -0
  53. data/vendor/libgit2/deps/pcre/cmake/FindEditline.cmake +17 -0
  54. data/vendor/libgit2/deps/pcre/cmake/FindPackageHandleStandardArgs.cmake +58 -0
  55. data/vendor/libgit2/deps/pcre/cmake/FindReadline.cmake +29 -0
  56. data/vendor/libgit2/deps/pcre/config.h.in +57 -0
  57. data/vendor/libgit2/deps/pcre/pcre.h +641 -0
  58. data/vendor/libgit2/deps/pcre/pcre_byte_order.c +319 -0
  59. data/vendor/libgit2/deps/pcre/pcre_chartables.c +198 -0
  60. data/vendor/libgit2/deps/pcre/pcre_compile.c +9800 -0
  61. data/vendor/libgit2/deps/pcre/pcre_config.c +190 -0
  62. data/vendor/libgit2/deps/pcre/pcre_dfa_exec.c +3676 -0
  63. data/vendor/libgit2/deps/pcre/pcre_exec.c +7173 -0
  64. data/vendor/libgit2/deps/pcre/pcre_fullinfo.c +245 -0
  65. data/vendor/libgit2/deps/pcre/pcre_get.c +669 -0
  66. data/vendor/libgit2/deps/pcre/pcre_globals.c +86 -0
  67. data/vendor/libgit2/deps/pcre/pcre_internal.h +2787 -0
  68. data/vendor/libgit2/deps/pcre/pcre_jit_compile.c +11913 -0
  69. data/vendor/libgit2/deps/pcre/pcre_maketables.c +156 -0
  70. data/vendor/libgit2/deps/pcre/pcre_newline.c +210 -0
  71. data/vendor/libgit2/deps/pcre/pcre_ord2utf8.c +94 -0
  72. data/vendor/libgit2/deps/pcre/pcre_printint.c +834 -0
  73. data/vendor/libgit2/deps/pcre/pcre_refcount.c +92 -0
  74. data/vendor/libgit2/deps/pcre/pcre_string_utils.c +211 -0
  75. data/vendor/libgit2/deps/pcre/pcre_study.c +1686 -0
  76. data/vendor/libgit2/deps/pcre/pcre_tables.c +727 -0
  77. data/vendor/libgit2/deps/pcre/pcre_ucd.c +3644 -0
  78. data/vendor/libgit2/deps/pcre/pcre_valid_utf8.c +301 -0
  79. data/vendor/libgit2/deps/pcre/pcre_version.c +98 -0
  80. data/vendor/libgit2/deps/pcre/pcre_xclass.c +268 -0
  81. data/vendor/libgit2/deps/pcre/pcreposix.c +421 -0
  82. data/vendor/libgit2/deps/pcre/pcreposix.h +117 -0
  83. data/vendor/libgit2/deps/pcre/ucp.h +224 -0
  84. data/vendor/libgit2/deps/zlib/adler32.c +0 -7
  85. data/vendor/libgit2/deps/zlib/crc32.c +0 -7
  86. data/vendor/libgit2/include/git2.h +2 -0
  87. data/vendor/libgit2/include/git2/apply.h +22 -2
  88. data/vendor/libgit2/include/git2/attr.h +23 -13
  89. data/vendor/libgit2/include/git2/blame.h +2 -2
  90. data/vendor/libgit2/include/git2/blob.h +44 -12
  91. data/vendor/libgit2/include/git2/branch.h +74 -57
  92. data/vendor/libgit2/include/git2/buffer.h +20 -14
  93. data/vendor/libgit2/include/git2/cert.h +135 -0
  94. data/vendor/libgit2/include/git2/checkout.h +46 -14
  95. data/vendor/libgit2/include/git2/cherrypick.h +3 -3
  96. data/vendor/libgit2/include/git2/clone.h +2 -2
  97. data/vendor/libgit2/include/git2/commit.h +23 -1
  98. data/vendor/libgit2/include/git2/common.h +15 -6
  99. data/vendor/libgit2/include/git2/config.h +12 -12
  100. data/vendor/libgit2/include/git2/cred_helpers.h +4 -42
  101. data/vendor/libgit2/include/git2/credential.h +314 -0
  102. data/vendor/libgit2/include/git2/credential_helpers.h +52 -0
  103. data/vendor/libgit2/include/git2/deprecated.h +314 -3
  104. data/vendor/libgit2/include/git2/describe.h +4 -4
  105. data/vendor/libgit2/include/git2/diff.h +16 -14
  106. data/vendor/libgit2/include/git2/errors.h +4 -2
  107. data/vendor/libgit2/include/git2/filter.h +8 -0
  108. data/vendor/libgit2/include/git2/index.h +2 -1
  109. data/vendor/libgit2/include/git2/indexer.h +48 -4
  110. data/vendor/libgit2/include/git2/merge.h +6 -10
  111. data/vendor/libgit2/include/git2/net.h +0 -5
  112. data/vendor/libgit2/include/git2/object.h +2 -14
  113. data/vendor/libgit2/include/git2/odb.h +3 -2
  114. data/vendor/libgit2/include/git2/odb_backend.h +5 -4
  115. data/vendor/libgit2/include/git2/oid.h +11 -6
  116. data/vendor/libgit2/include/git2/pack.h +12 -1
  117. data/vendor/libgit2/include/git2/proxy.h +6 -4
  118. data/vendor/libgit2/include/git2/rebase.h +46 -2
  119. data/vendor/libgit2/include/git2/refs.h +19 -0
  120. data/vendor/libgit2/include/git2/remote.h +40 -15
  121. data/vendor/libgit2/include/git2/repository.h +24 -2
  122. data/vendor/libgit2/include/git2/revert.h +1 -1
  123. data/vendor/libgit2/include/git2/revwalk.h +7 -3
  124. data/vendor/libgit2/include/git2/stash.h +4 -4
  125. data/vendor/libgit2/include/git2/status.h +25 -16
  126. data/vendor/libgit2/include/git2/submodule.h +20 -3
  127. data/vendor/libgit2/include/git2/sys/alloc.h +9 -9
  128. data/vendor/libgit2/include/git2/sys/cred.h +15 -0
  129. data/vendor/libgit2/include/git2/sys/credential.h +90 -0
  130. data/vendor/libgit2/include/git2/sys/index.h +4 -2
  131. data/vendor/libgit2/include/git2/sys/mempack.h +2 -1
  132. data/vendor/libgit2/include/git2/sys/merge.h +1 -1
  133. data/vendor/libgit2/include/git2/sys/odb_backend.h +48 -4
  134. data/vendor/libgit2/include/git2/sys/refdb_backend.h +57 -21
  135. data/vendor/libgit2/include/git2/sys/repository.h +17 -6
  136. data/vendor/libgit2/include/git2/sys/transport.h +4 -4
  137. data/vendor/libgit2/include/git2/tag.h +11 -2
  138. data/vendor/libgit2/include/git2/trace.h +2 -2
  139. data/vendor/libgit2/include/git2/transport.h +11 -340
  140. data/vendor/libgit2/include/git2/tree.h +5 -3
  141. data/vendor/libgit2/include/git2/types.h +4 -89
  142. data/vendor/libgit2/include/git2/version.h +4 -4
  143. data/vendor/libgit2/include/git2/worktree.h +5 -5
  144. data/vendor/libgit2/src/CMakeLists.txt +89 -224
  145. data/vendor/libgit2/src/alloc.c +2 -14
  146. data/vendor/libgit2/src/{stdalloc.c → allocators/stdalloc.c} +3 -4
  147. data/vendor/libgit2/src/{stdalloc.h → allocators/stdalloc.h} +4 -4
  148. data/vendor/libgit2/src/allocators/win32_crtdbg.c +118 -0
  149. data/vendor/libgit2/src/{transports/cred.h → allocators/win32_crtdbg.h} +5 -4
  150. data/vendor/libgit2/src/apply.c +31 -15
  151. data/vendor/libgit2/src/attr.c +70 -64
  152. data/vendor/libgit2/src/attr_file.c +189 -96
  153. data/vendor/libgit2/src/attr_file.h +9 -9
  154. data/vendor/libgit2/src/attrcache.c +47 -47
  155. data/vendor/libgit2/src/attrcache.h +2 -1
  156. data/vendor/libgit2/src/blame.c +17 -5
  157. data/vendor/libgit2/src/blame.h +1 -1
  158. data/vendor/libgit2/src/blame_git.c +21 -7
  159. data/vendor/libgit2/src/blob.c +81 -17
  160. data/vendor/libgit2/src/blob.h +2 -2
  161. data/vendor/libgit2/src/branch.c +60 -32
  162. data/vendor/libgit2/src/buffer.c +5 -0
  163. data/vendor/libgit2/src/buffer.h +1 -0
  164. data/vendor/libgit2/src/cache.c +26 -33
  165. data/vendor/libgit2/src/cache.h +1 -1
  166. data/vendor/libgit2/src/cc-compat.h +5 -0
  167. data/vendor/libgit2/src/checkout.c +26 -16
  168. data/vendor/libgit2/src/cherrypick.c +7 -1
  169. data/vendor/libgit2/src/clone.c +29 -7
  170. data/vendor/libgit2/src/clone.h +4 -0
  171. data/vendor/libgit2/src/commit.c +70 -22
  172. data/vendor/libgit2/src/commit.h +6 -0
  173. data/vendor/libgit2/src/commit_list.c +28 -76
  174. data/vendor/libgit2/src/commit_list.h +2 -2
  175. data/vendor/libgit2/src/common.h +3 -75
  176. data/vendor/libgit2/src/config.c +31 -40
  177. data/vendor/libgit2/src/config.h +7 -6
  178. data/vendor/libgit2/src/config_backend.h +12 -0
  179. data/vendor/libgit2/src/config_cache.c +39 -39
  180. data/vendor/libgit2/src/config_entries.c +69 -99
  181. data/vendor/libgit2/src/config_entries.h +1 -0
  182. data/vendor/libgit2/src/config_file.c +337 -380
  183. data/vendor/libgit2/src/config_mem.c +12 -16
  184. data/vendor/libgit2/src/config_parse.c +49 -29
  185. data/vendor/libgit2/src/config_parse.h +13 -12
  186. data/vendor/libgit2/src/config_snapshot.c +206 -0
  187. data/vendor/libgit2/src/crlf.c +14 -14
  188. data/vendor/libgit2/src/describe.c +21 -20
  189. data/vendor/libgit2/src/diff.c +43 -66
  190. data/vendor/libgit2/src/diff.h +4 -3
  191. data/vendor/libgit2/src/diff_driver.c +37 -38
  192. data/vendor/libgit2/src/diff_file.c +12 -10
  193. data/vendor/libgit2/src/diff_file.h +2 -2
  194. data/vendor/libgit2/src/diff_generate.c +26 -26
  195. data/vendor/libgit2/src/diff_generate.h +2 -2
  196. data/vendor/libgit2/src/diff_parse.c +1 -1
  197. data/vendor/libgit2/src/diff_print.c +25 -13
  198. data/vendor/libgit2/src/diff_stats.c +1 -1
  199. data/vendor/libgit2/src/diff_tform.c +11 -11
  200. data/vendor/libgit2/src/errors.c +21 -25
  201. data/vendor/libgit2/src/errors.h +81 -0
  202. data/vendor/libgit2/src/features.h.in +9 -2
  203. data/vendor/libgit2/src/fetch.c +7 -2
  204. data/vendor/libgit2/src/fetchhead.c +9 -9
  205. data/vendor/libgit2/src/filebuf.c +1 -1
  206. data/vendor/libgit2/src/filebuf.h +1 -1
  207. data/vendor/libgit2/src/filter.c +16 -8
  208. data/vendor/libgit2/src/{fileops.c → futils.c} +20 -17
  209. data/vendor/libgit2/src/{fileops.h → futils.h} +5 -5
  210. data/vendor/libgit2/src/hash.c +61 -0
  211. data/vendor/libgit2/src/hash.h +19 -21
  212. data/vendor/libgit2/src/hash/sha1.h +38 -0
  213. data/vendor/libgit2/src/hash/{hash_collisiondetect.h → sha1/collisiondetect.c} +14 -17
  214. data/vendor/libgit2/src/hash/sha1/collisiondetect.h +19 -0
  215. data/vendor/libgit2/src/hash/{hash_common_crypto.h → sha1/common_crypto.c} +15 -19
  216. data/vendor/libgit2/src/hash/sha1/common_crypto.h +19 -0
  217. data/vendor/libgit2/src/hash/{hash_generic.c → sha1/generic.c} +22 -10
  218. data/vendor/libgit2/src/hash/{hash_generic.h → sha1/generic.h} +4 -14
  219. data/vendor/libgit2/src/hash/{hash_mbedtls.c → sha1/mbedtls.c} +15 -7
  220. data/vendor/libgit2/src/hash/{hash_mbedtls.h → sha1/mbedtls.h} +6 -11
  221. data/vendor/libgit2/src/hash/{hash_openssl.h → sha1/openssl.c} +14 -18
  222. data/vendor/libgit2/src/hash/sha1/openssl.h +19 -0
  223. data/vendor/libgit2/src/hash/{sha1dc → sha1/sha1dc}/sha1.c +14 -3
  224. data/vendor/libgit2/src/hash/{sha1dc → sha1/sha1dc}/sha1.h +0 -0
  225. data/vendor/libgit2/src/hash/{sha1dc → sha1/sha1dc}/ubc_check.c +0 -0
  226. data/vendor/libgit2/src/hash/{sha1dc → sha1/sha1dc}/ubc_check.h +0 -0
  227. data/vendor/libgit2/src/hash/{hash_win32.c → sha1/win32.c} +34 -24
  228. data/vendor/libgit2/src/hash/{hash_win32.h → sha1/win32.h} +6 -19
  229. data/vendor/libgit2/src/hashsig.c +1 -1
  230. data/vendor/libgit2/src/idxmap.c +91 -65
  231. data/vendor/libgit2/src/idxmap.h +151 -15
  232. data/vendor/libgit2/src/ignore.c +26 -35
  233. data/vendor/libgit2/src/index.c +103 -81
  234. data/vendor/libgit2/src/index.h +1 -1
  235. data/vendor/libgit2/src/indexer.c +69 -70
  236. data/vendor/libgit2/src/integer.h +11 -4
  237. data/vendor/libgit2/src/iterator.c +32 -28
  238. data/vendor/libgit2/src/iterator.h +8 -8
  239. data/vendor/libgit2/src/map.h +1 -1
  240. data/vendor/libgit2/src/merge.c +55 -41
  241. data/vendor/libgit2/src/merge.h +2 -2
  242. data/vendor/libgit2/src/merge_driver.c +5 -5
  243. data/vendor/libgit2/src/merge_file.c +1 -1
  244. data/vendor/libgit2/src/mwindow.c +18 -23
  245. data/vendor/libgit2/src/mwindow.h +4 -4
  246. data/vendor/libgit2/src/net.c +411 -0
  247. data/vendor/libgit2/src/net.h +57 -0
  248. data/vendor/libgit2/src/netops.c +6 -222
  249. data/vendor/libgit2/src/netops.h +1 -37
  250. data/vendor/libgit2/src/notes.c +2 -2
  251. data/vendor/libgit2/src/object.c +3 -3
  252. data/vendor/libgit2/src/object.h +2 -0
  253. data/vendor/libgit2/src/odb.c +41 -23
  254. data/vendor/libgit2/src/odb.h +3 -2
  255. data/vendor/libgit2/src/odb_loose.c +17 -10
  256. data/vendor/libgit2/src/odb_mempack.c +13 -24
  257. data/vendor/libgit2/src/odb_pack.c +4 -4
  258. data/vendor/libgit2/src/offmap.c +43 -55
  259. data/vendor/libgit2/src/offmap.h +102 -24
  260. data/vendor/libgit2/src/oid.c +19 -8
  261. data/vendor/libgit2/src/oidmap.c +39 -57
  262. data/vendor/libgit2/src/oidmap.h +99 -19
  263. data/vendor/libgit2/src/pack-objects.c +25 -32
  264. data/vendor/libgit2/src/pack-objects.h +1 -1
  265. data/vendor/libgit2/src/pack.c +97 -129
  266. data/vendor/libgit2/src/pack.h +15 -18
  267. data/vendor/libgit2/src/parse.c +10 -0
  268. data/vendor/libgit2/src/parse.h +3 -3
  269. data/vendor/libgit2/src/patch.c +1 -1
  270. data/vendor/libgit2/src/patch_generate.c +1 -1
  271. data/vendor/libgit2/src/patch_parse.c +30 -9
  272. data/vendor/libgit2/src/path.c +43 -6
  273. data/vendor/libgit2/src/path.h +2 -0
  274. data/vendor/libgit2/src/pathspec.c +14 -14
  275. data/vendor/libgit2/src/pool.c +26 -22
  276. data/vendor/libgit2/src/pool.h +7 -7
  277. data/vendor/libgit2/src/posix.c +7 -7
  278. data/vendor/libgit2/src/posix.h +12 -1
  279. data/vendor/libgit2/src/proxy.c +7 -2
  280. data/vendor/libgit2/src/push.c +10 -5
  281. data/vendor/libgit2/src/reader.c +2 -2
  282. data/vendor/libgit2/src/rebase.c +87 -28
  283. data/vendor/libgit2/src/refdb.c +12 -0
  284. data/vendor/libgit2/src/refdb_fs.c +215 -169
  285. data/vendor/libgit2/src/reflog.c +11 -13
  286. data/vendor/libgit2/src/refs.c +34 -23
  287. data/vendor/libgit2/src/refs.h +8 -1
  288. data/vendor/libgit2/src/refspec.c +9 -16
  289. data/vendor/libgit2/src/regexp.c +221 -0
  290. data/vendor/libgit2/src/regexp.h +97 -0
  291. data/vendor/libgit2/src/remote.c +57 -55
  292. data/vendor/libgit2/src/remote.h +2 -2
  293. data/vendor/libgit2/src/repository.c +120 -103
  294. data/vendor/libgit2/src/repository.h +49 -40
  295. data/vendor/libgit2/src/revert.c +6 -1
  296. data/vendor/libgit2/src/revparse.c +18 -19
  297. data/vendor/libgit2/src/revwalk.c +71 -33
  298. data/vendor/libgit2/src/revwalk.h +20 -0
  299. data/vendor/libgit2/src/settings.c +13 -1
  300. data/vendor/libgit2/src/sortedcache.c +12 -26
  301. data/vendor/libgit2/src/sortedcache.h +1 -1
  302. data/vendor/libgit2/src/stash.c +45 -65
  303. data/vendor/libgit2/src/status.c +17 -11
  304. data/vendor/libgit2/src/streams/openssl.c +53 -1
  305. data/vendor/libgit2/src/streams/socket.c +2 -2
  306. data/vendor/libgit2/src/strmap.c +37 -84
  307. data/vendor/libgit2/src/strmap.h +105 -33
  308. data/vendor/libgit2/src/submodule.c +151 -126
  309. data/vendor/libgit2/src/submodule.h +1 -1
  310. data/vendor/libgit2/src/tag.c +10 -2
  311. data/vendor/libgit2/src/trace.c +1 -1
  312. data/vendor/libgit2/src/trace.h +3 -3
  313. data/vendor/libgit2/src/trailer.c +46 -32
  314. data/vendor/libgit2/src/transaction.c +3 -8
  315. data/vendor/libgit2/src/transports/auth.c +16 -15
  316. data/vendor/libgit2/src/transports/auth.h +18 -11
  317. data/vendor/libgit2/src/transports/auth_negotiate.c +64 -33
  318. data/vendor/libgit2/src/transports/auth_negotiate.h +2 -2
  319. data/vendor/libgit2/src/transports/auth_ntlm.c +223 -0
  320. data/vendor/libgit2/src/transports/auth_ntlm.h +38 -0
  321. data/vendor/libgit2/src/transports/credential.c +476 -0
  322. data/vendor/libgit2/src/transports/{cred_helpers.c → credential_helpers.c} +21 -8
  323. data/vendor/libgit2/src/transports/git.c +11 -16
  324. data/vendor/libgit2/src/transports/http.c +488 -1248
  325. data/vendor/libgit2/src/transports/http.h +4 -1
  326. data/vendor/libgit2/src/transports/httpclient.c +1526 -0
  327. data/vendor/libgit2/src/transports/httpclient.h +190 -0
  328. data/vendor/libgit2/src/transports/local.c +10 -10
  329. data/vendor/libgit2/src/transports/smart.c +19 -19
  330. data/vendor/libgit2/src/transports/smart.h +3 -3
  331. data/vendor/libgit2/src/transports/smart_protocol.c +40 -64
  332. data/vendor/libgit2/src/transports/ssh.c +77 -59
  333. data/vendor/libgit2/src/transports/winhttp.c +266 -241
  334. data/vendor/libgit2/src/tree-cache.c +14 -7
  335. data/vendor/libgit2/src/tree.c +16 -26
  336. data/vendor/libgit2/src/unix/map.c +1 -1
  337. data/vendor/libgit2/src/unix/posix.h +2 -12
  338. data/vendor/libgit2/src/userdiff.h +3 -1
  339. data/vendor/libgit2/src/util.c +51 -53
  340. data/vendor/libgit2/src/util.h +16 -21
  341. data/vendor/libgit2/src/wildmatch.c +320 -0
  342. data/vendor/libgit2/src/wildmatch.h +23 -0
  343. data/vendor/libgit2/src/win32/map.c +3 -5
  344. data/vendor/libgit2/src/win32/path_w32.c +12 -2
  345. data/vendor/libgit2/src/win32/path_w32.h +0 -29
  346. data/vendor/libgit2/src/win32/posix.h +1 -4
  347. data/vendor/libgit2/src/win32/posix_w32.c +48 -5
  348. data/vendor/libgit2/src/win32/precompiled.h +0 -2
  349. data/vendor/libgit2/src/win32/thread.c +5 -5
  350. data/vendor/libgit2/src/win32/w32_buffer.c +7 -3
  351. data/vendor/libgit2/src/win32/w32_common.h +39 -0
  352. data/vendor/libgit2/src/win32/w32_crtdbg_stacktrace.c +0 -93
  353. data/vendor/libgit2/src/win32/w32_crtdbg_stacktrace.h +0 -2
  354. data/vendor/libgit2/src/win32/w32_stack.c +4 -9
  355. data/vendor/libgit2/src/win32/w32_stack.h +3 -3
  356. data/vendor/libgit2/src/win32/w32_util.c +31 -0
  357. data/vendor/libgit2/src/win32/w32_util.h +6 -32
  358. data/vendor/libgit2/src/worktree.c +36 -22
  359. data/vendor/libgit2/src/xdiff/xdiffi.c +1 -1
  360. data/vendor/libgit2/src/xdiff/xmerge.c +12 -0
  361. data/vendor/libgit2/src/xdiff/xpatience.c +3 -0
  362. data/vendor/libgit2/src/zstream.c +5 -0
  363. data/vendor/libgit2/src/zstream.h +1 -0
  364. metadata +108 -38
  365. data/vendor/libgit2/deps/regex/CMakeLists.txt +0 -2
  366. data/vendor/libgit2/deps/regex/COPYING +0 -502
  367. data/vendor/libgit2/deps/regex/config.h +0 -7
  368. data/vendor/libgit2/deps/regex/regcomp.c +0 -3857
  369. data/vendor/libgit2/deps/regex/regex.c +0 -92
  370. data/vendor/libgit2/deps/regex/regex.h +0 -582
  371. data/vendor/libgit2/deps/regex/regex_internal.c +0 -1744
  372. data/vendor/libgit2/deps/regex/regex_internal.h +0 -819
  373. data/vendor/libgit2/deps/regex/regexec.c +0 -4369
  374. data/vendor/libgit2/include/git2/inttypes.h +0 -309
  375. data/vendor/libgit2/include/git2/sys/time.h +0 -31
  376. data/vendor/libgit2/libgit2.pc.in +0 -13
  377. data/vendor/libgit2/src/fnmatch.c +0 -248
  378. data/vendor/libgit2/src/fnmatch.h +0 -48
  379. data/vendor/libgit2/src/transports/cred.c +0 -390
@@ -66,6 +66,18 @@ static void refdb_free_backend(git_refdb *db)
66
66
 
67
67
  int git_refdb_set_backend(git_refdb *db, git_refdb_backend *backend)
68
68
  {
69
+ GIT_ERROR_CHECK_VERSION(backend, GIT_REFDB_BACKEND_VERSION, "git_refdb_backend");
70
+
71
+ if (!backend->exists || !backend->lookup || !backend->iterator ||
72
+ !backend->write || !backend->rename || !backend->del ||
73
+ !backend->has_log || !backend->ensure_log || !backend->free ||
74
+ !backend->reflog_read || !backend->reflog_write ||
75
+ !backend->reflog_rename || !backend->reflog_delete ||
76
+ (backend->lock && !backend->unlock)) {
77
+ git_error_set(GIT_ERROR_REFERENCE, "incomplete refdb backend implementation");
78
+ return GIT_EINVALID;
79
+ }
80
+
69
81
  refdb_free_backend(db);
70
82
  db->backend = backend;
71
83
 
@@ -10,14 +10,16 @@
10
10
  #include "refs.h"
11
11
  #include "hash.h"
12
12
  #include "repository.h"
13
- #include "fileops.h"
13
+ #include "futils.h"
14
14
  #include "filebuf.h"
15
15
  #include "pack.h"
16
+ #include "parse.h"
16
17
  #include "reflog.h"
17
18
  #include "refdb.h"
18
19
  #include "iterator.h"
19
20
  #include "sortedcache.h"
20
21
  #include "signature.h"
22
+ #include "wildmatch.h"
21
23
 
22
24
  #include <git2/tag.h>
23
25
  #include <git2/object.h>
@@ -327,21 +329,33 @@ static int refdb_fs_backend__exists(
327
329
  git_refdb_backend *_backend,
328
330
  const char *ref_name)
329
331
  {
330
- refdb_fs_backend *backend = (refdb_fs_backend *)_backend;
332
+ refdb_fs_backend *backend = GIT_CONTAINER_OF(_backend, refdb_fs_backend, parent);
331
333
  git_buf ref_path = GIT_BUF_INIT;
332
334
  int error;
333
335
 
334
336
  assert(backend);
335
337
 
336
- if ((error = packed_reload(backend)) < 0 ||
337
- (error = git_buf_joinpath(&ref_path, backend->gitpath, ref_name)) < 0)
338
- return error;
338
+ *exists = 0;
339
+
340
+ if ((error = git_buf_joinpath(&ref_path, backend->gitpath, ref_name)) < 0)
341
+ goto out;
342
+
343
+ if (git_path_isfile(ref_path.ptr)) {
344
+ *exists = 1;
345
+ goto out;
346
+ }
347
+
348
+ if ((error = packed_reload(backend)) < 0)
349
+ goto out;
339
350
 
340
- *exists = git_path_isfile(ref_path.ptr) ||
341
- (git_sortedcache_lookup(backend->refcache, ref_name) != NULL);
351
+ if (git_sortedcache_lookup(backend->refcache, ref_name) != NULL) {
352
+ *exists = 1;
353
+ goto out;
354
+ }
342
355
 
356
+ out:
343
357
  git_buf_dispose(&ref_path);
344
- return 0;
358
+ return error;
345
359
  }
346
360
 
347
361
  static const char *loose_parse_symbolic(git_buf *file_content)
@@ -457,7 +471,7 @@ static int refdb_fs_backend__lookup(
457
471
  git_refdb_backend *_backend,
458
472
  const char *ref_name)
459
473
  {
460
- refdb_fs_backend *backend = (refdb_fs_backend *)_backend;
474
+ refdb_fs_backend *backend = GIT_CONTAINER_OF(_backend, refdb_fs_backend, parent);
461
475
  int error;
462
476
 
463
477
  assert(backend);
@@ -490,7 +504,7 @@ typedef struct {
490
504
 
491
505
  static void refdb_fs_backend__iterator_free(git_reference_iterator *_iter)
492
506
  {
493
- refdb_fs_iter *iter = (refdb_fs_iter *) _iter;
507
+ refdb_fs_iter *iter = GIT_CONTAINER_OF(_iter, refdb_fs_iter, parent);
494
508
 
495
509
  git_vector_free(&iter->loose);
496
510
  git_pool_clear(&iter->pool);
@@ -552,7 +566,6 @@ static int iter_load_loose_paths(refdb_fs_backend *backend, refdb_fs_iter *iter)
552
566
 
553
567
  while (!error && !git_iterator_advance(&entry, fsit)) {
554
568
  const char *ref_name;
555
- struct packref *ref;
556
569
  char *ref_dup;
557
570
 
558
571
  git_buf_truncate(&path, ref_prefix_len);
@@ -560,15 +573,9 @@ static int iter_load_loose_paths(refdb_fs_backend *backend, refdb_fs_iter *iter)
560
573
  ref_name = git_buf_cstr(&path);
561
574
 
562
575
  if (git__suffixcmp(ref_name, ".lock") == 0 ||
563
- (iter->glob && p_fnmatch(iter->glob, ref_name, 0) != 0))
576
+ (iter->glob && wildmatch(iter->glob, ref_name, 0) != 0))
564
577
  continue;
565
578
 
566
- git_sortedcache_rlock(backend->refcache);
567
- ref = git_sortedcache_lookup(backend->refcache, ref_name);
568
- if (ref)
569
- ref->flags |= PACKREF_SHADOWED;
570
- git_sortedcache_runlock(backend->refcache);
571
-
572
579
  ref_dup = git_pool_strdup(&iter->pool, ref_name);
573
580
  if (!ref_dup)
574
581
  error = -1;
@@ -586,24 +593,24 @@ static int refdb_fs_backend__iterator_next(
586
593
  git_reference **out, git_reference_iterator *_iter)
587
594
  {
588
595
  int error = GIT_ITEROVER;
589
- refdb_fs_iter *iter = (refdb_fs_iter *)_iter;
590
- refdb_fs_backend *backend = (refdb_fs_backend *)iter->parent.db->backend;
596
+ refdb_fs_iter *iter = GIT_CONTAINER_OF(_iter, refdb_fs_iter, parent);
597
+ refdb_fs_backend *backend = GIT_CONTAINER_OF(iter->parent.db->backend, refdb_fs_backend, parent);
591
598
  struct packref *ref;
592
599
 
593
600
  while (iter->loose_pos < iter->loose.length) {
594
601
  const char *path = git_vector_get(&iter->loose, iter->loose_pos++);
595
602
 
596
- if (loose_lookup(out, backend, path) == 0)
603
+ if (loose_lookup(out, backend, path) == 0) {
604
+ ref = git_sortedcache_lookup(iter->cache, path);
605
+ if (ref)
606
+ ref->flags |= PACKREF_SHADOWED;
607
+
597
608
  return 0;
609
+ }
598
610
 
599
611
  git_error_clear();
600
612
  }
601
613
 
602
- if (!iter->cache) {
603
- if ((error = git_sortedcache_copy(&iter->cache, backend->refcache, 1, NULL, NULL)) < 0)
604
- return error;
605
- }
606
-
607
614
  error = GIT_ITEROVER;
608
615
  while (iter->packed_pos < git_sortedcache_entrycount(iter->cache)) {
609
616
  ref = git_sortedcache_entry(iter->cache, iter->packed_pos++);
@@ -612,7 +619,7 @@ static int refdb_fs_backend__iterator_next(
612
619
 
613
620
  if (ref->flags & PACKREF_SHADOWED)
614
621
  continue;
615
- if (iter->glob && p_fnmatch(iter->glob, ref->name, 0) != 0)
622
+ if (iter->glob && wildmatch(iter->glob, ref->name, 0) != 0)
616
623
  continue;
617
624
 
618
625
  *out = git_reference__alloc(ref->name, &ref->oid, &ref->peel);
@@ -627,14 +634,19 @@ static int refdb_fs_backend__iterator_next_name(
627
634
  const char **out, git_reference_iterator *_iter)
628
635
  {
629
636
  int error = GIT_ITEROVER;
630
- refdb_fs_iter *iter = (refdb_fs_iter *)_iter;
631
- refdb_fs_backend *backend = (refdb_fs_backend *)iter->parent.db->backend;
637
+ refdb_fs_iter *iter = GIT_CONTAINER_OF(_iter, refdb_fs_iter, parent);
638
+ refdb_fs_backend *backend = GIT_CONTAINER_OF(iter->parent.db->backend, refdb_fs_backend, parent);
632
639
  struct packref *ref;
633
640
 
634
641
  while (iter->loose_pos < iter->loose.length) {
635
642
  const char *path = git_vector_get(&iter->loose, iter->loose_pos++);
643
+ struct packref *ref;
636
644
 
637
645
  if (loose_lookup(NULL, backend, path) == 0) {
646
+ ref = git_sortedcache_lookup(iter->cache, path);
647
+ if (ref)
648
+ ref->flags |= PACKREF_SHADOWED;
649
+
638
650
  *out = path;
639
651
  return 0;
640
652
  }
@@ -642,11 +654,6 @@ static int refdb_fs_backend__iterator_next_name(
642
654
  git_error_clear();
643
655
  }
644
656
 
645
- if (!iter->cache) {
646
- if ((error = git_sortedcache_copy(&iter->cache, backend->refcache, 1, NULL, NULL)) < 0)
647
- return error;
648
- }
649
-
650
657
  error = GIT_ITEROVER;
651
658
  while (iter->packed_pos < git_sortedcache_entrycount(iter->cache)) {
652
659
  ref = git_sortedcache_entry(iter->cache, iter->packed_pos++);
@@ -655,7 +662,7 @@ static int refdb_fs_backend__iterator_next_name(
655
662
 
656
663
  if (ref->flags & PACKREF_SHADOWED)
657
664
  continue;
658
- if (iter->glob && p_fnmatch(iter->glob, ref->name, 0) != 0)
665
+ if (iter->glob && wildmatch(iter->glob, ref->name, 0) != 0)
659
666
  continue;
660
667
 
661
668
  *out = ref->name;
@@ -669,40 +676,44 @@ static int refdb_fs_backend__iterator_next_name(
669
676
  static int refdb_fs_backend__iterator(
670
677
  git_reference_iterator **out, git_refdb_backend *_backend, const char *glob)
671
678
  {
679
+ refdb_fs_backend *backend = GIT_CONTAINER_OF(_backend, refdb_fs_backend, parent);
680
+ refdb_fs_iter *iter = NULL;
672
681
  int error;
673
- refdb_fs_iter *iter;
674
- refdb_fs_backend *backend = (refdb_fs_backend *)_backend;
675
682
 
676
683
  assert(backend);
677
684
 
678
- if ((error = packed_reload(backend)) < 0)
679
- return error;
680
-
681
685
  iter = git__calloc(1, sizeof(refdb_fs_iter));
682
686
  GIT_ERROR_CHECK_ALLOC(iter);
683
687
 
684
688
  git_pool_init(&iter->pool, 1);
685
689
 
686
- if (git_vector_init(&iter->loose, 8, NULL) < 0)
687
- goto fail;
690
+ if ((error = git_vector_init(&iter->loose, 8, NULL)) < 0)
691
+ goto out;
688
692
 
689
693
  if (glob != NULL &&
690
- (iter->glob = git_pool_strdup(&iter->pool, glob)) == NULL)
691
- goto fail;
694
+ (iter->glob = git_pool_strdup(&iter->pool, glob)) == NULL) {
695
+ error = GIT_ERROR_NOMEMORY;
696
+ goto out;
697
+ }
698
+
699
+ if ((error = iter_load_loose_paths(backend, iter)) < 0)
700
+ goto out;
701
+
702
+ if ((error = packed_reload(backend)) < 0)
703
+ goto out;
704
+
705
+ if ((error = git_sortedcache_copy(&iter->cache, backend->refcache, 1, NULL, NULL)) < 0)
706
+ goto out;
692
707
 
693
708
  iter->parent.next = refdb_fs_backend__iterator_next;
694
709
  iter->parent.next_name = refdb_fs_backend__iterator_next_name;
695
710
  iter->parent.free = refdb_fs_backend__iterator_free;
696
711
 
697
- if (iter_load_loose_paths(backend, iter) < 0)
698
- goto fail;
699
-
700
712
  *out = (git_reference_iterator *)iter;
701
- return 0;
702
-
703
- fail:
704
- refdb_fs_backend__iterator_free((git_reference_iterator *)iter);
705
- return -1;
713
+ out:
714
+ if (error)
715
+ refdb_fs_backend__iterator_free((git_reference_iterator *)iter);
716
+ return error;
706
717
  }
707
718
 
708
719
  static bool ref_is_available(
@@ -829,7 +840,7 @@ static int refdb_fs_backend__lock(void **out, git_refdb_backend *_backend, const
829
840
  {
830
841
  int error;
831
842
  git_filebuf *lock;
832
- refdb_fs_backend *backend = (refdb_fs_backend *) _backend;
843
+ refdb_fs_backend *backend = GIT_CONTAINER_OF(_backend, refdb_fs_backend, parent);
833
844
 
834
845
  lock = git__calloc(1, sizeof(git_filebuf));
835
846
  GIT_ERROR_CHECK_ALLOC(lock);
@@ -848,16 +859,17 @@ static int refdb_fs_backend__write_tail(
848
859
  const git_reference *ref,
849
860
  git_filebuf *file,
850
861
  int update_reflog,
851
- const git_signature *who,
852
- const char *message,
853
862
  const git_oid *old_id,
854
- const char *old_target);
863
+ const char *old_target,
864
+ const git_signature *who,
865
+ const char *message);
855
866
 
856
867
  static int refdb_fs_backend__delete_tail(
857
868
  git_refdb_backend *_backend,
858
869
  git_filebuf *file,
859
870
  const char *ref_name,
860
- const git_oid *old_id, const char *old_target);
871
+ const git_oid *old_id,
872
+ const char *old_target);
861
873
 
862
874
  static int refdb_fs_backend__unlock(git_refdb_backend *backend, void *payload, int success, int update_reflog,
863
875
  const git_reference *ref, const git_signature *sig, const char *message)
@@ -868,7 +880,7 @@ static int refdb_fs_backend__unlock(git_refdb_backend *backend, void *payload, i
868
880
  if (success == 2)
869
881
  error = refdb_fs_backend__delete_tail(backend, lock, ref->name, NULL, NULL);
870
882
  else if (success)
871
- error = refdb_fs_backend__write_tail(backend, ref, lock, update_reflog, sig, message, NULL, NULL);
883
+ error = refdb_fs_backend__write_tail(backend, ref, lock, update_reflog, NULL, NULL, sig, message);
872
884
  else
873
885
  git_filebuf_cleanup(lock);
874
886
 
@@ -1087,6 +1099,35 @@ fail:
1087
1099
  return error;
1088
1100
  }
1089
1101
 
1102
+ static int packed_delete(refdb_fs_backend *backend, const char *ref_name)
1103
+ {
1104
+ size_t pack_pos;
1105
+ int error, found = 0;
1106
+
1107
+ if ((error = packed_reload(backend)) < 0)
1108
+ goto cleanup;
1109
+
1110
+ if ((error = git_sortedcache_wlock(backend->refcache)) < 0)
1111
+ goto cleanup;
1112
+
1113
+ /* If a packed reference exists, remove it from the packfile and repack if necessary */
1114
+ error = git_sortedcache_lookup_index(&pack_pos, backend->refcache, ref_name);
1115
+ if (error == 0) {
1116
+ error = git_sortedcache_remove(backend->refcache, pack_pos);
1117
+ found = 1;
1118
+ }
1119
+ if (error == GIT_ENOTFOUND)
1120
+ error = 0;
1121
+
1122
+ git_sortedcache_wunlock(backend->refcache);
1123
+
1124
+ if (found)
1125
+ error = packed_write(backend);
1126
+
1127
+ cleanup:
1128
+ return error;
1129
+ }
1130
+
1090
1131
  static int reflog_append(refdb_fs_backend *backend, const git_reference *ref, const git_oid *old, const git_oid *new, const git_signature *author, const char *message);
1091
1132
  static int has_reflog(git_repository *repo, const char *name);
1092
1133
 
@@ -1094,7 +1135,7 @@ static int should_write_reflog(int *write, git_repository *repo, const char *nam
1094
1135
  {
1095
1136
  int error, logall;
1096
1137
 
1097
- error = git_repository__cvar(&logall, repo, GIT_CVAR_LOGALLREFUPDATES);
1138
+ error = git_repository__configmap_lookup(&logall, repo, GIT_CONFIGMAP_LOGALLREFUPDATES);
1098
1139
  if (error < 0)
1099
1140
  return error;
1100
1141
 
@@ -1239,7 +1280,7 @@ static int refdb_fs_backend__write(
1239
1280
  const git_oid *old_id,
1240
1281
  const char *old_target)
1241
1282
  {
1242
- refdb_fs_backend *backend = (refdb_fs_backend *)_backend;
1283
+ refdb_fs_backend *backend = GIT_CONTAINER_OF(_backend, refdb_fs_backend, parent);
1243
1284
  git_filebuf file = GIT_FILEBUF_INIT;
1244
1285
  int error = 0;
1245
1286
 
@@ -1252,7 +1293,7 @@ static int refdb_fs_backend__write(
1252
1293
  if ((error = loose_lock(&file, backend, ref->name)) < 0)
1253
1294
  return error;
1254
1295
 
1255
- return refdb_fs_backend__write_tail(_backend, ref, &file, true, who, message, old_id, old_target);
1296
+ return refdb_fs_backend__write_tail(_backend, ref, &file, true, old_id, old_target, who, message);
1256
1297
  }
1257
1298
 
1258
1299
  static int refdb_fs_backend__write_tail(
@@ -1260,12 +1301,12 @@ static int refdb_fs_backend__write_tail(
1260
1301
  const git_reference *ref,
1261
1302
  git_filebuf *file,
1262
1303
  int update_reflog,
1263
- const git_signature *who,
1264
- const char *message,
1265
1304
  const git_oid *old_id,
1266
- const char *old_target)
1305
+ const char *old_target,
1306
+ const git_signature *who,
1307
+ const char *message)
1267
1308
  {
1268
- refdb_fs_backend *backend = (refdb_fs_backend *)_backend;
1309
+ refdb_fs_backend *backend = GIT_CONTAINER_OF(_backend, refdb_fs_backend, parent);
1269
1310
  int error = 0, cmp = 0, should_write;
1270
1311
  const char *new_target = NULL;
1271
1312
  const git_oid *new_id = NULL;
@@ -1313,10 +1354,10 @@ on_error:
1313
1354
  return error;
1314
1355
  }
1315
1356
 
1316
- static void refdb_fs_backend__try_delete_empty_ref_hierarchie(
1357
+ static void refdb_fs_backend__prune_refs(
1317
1358
  refdb_fs_backend *backend,
1318
1359
  const char *ref_name,
1319
- bool reflog)
1360
+ const char *prefix)
1320
1361
  {
1321
1362
  git_buf relative_path = GIT_BUF_INIT;
1322
1363
  git_buf base_path = GIT_BUF_INIT;
@@ -1334,8 +1375,8 @@ static void refdb_fs_backend__try_delete_empty_ref_hierarchie(
1334
1375
 
1335
1376
  git_buf_truncate(&relative_path, commonlen);
1336
1377
 
1337
- if (reflog) {
1338
- if (git_buf_join3(&base_path, '/', backend->commonpath, GIT_REFLOG_DIR, git_buf_cstr(&relative_path)) < 0)
1378
+ if (prefix) {
1379
+ if (git_buf_join3(&base_path, '/', backend->commonpath, prefix, git_buf_cstr(&relative_path)) < 0)
1339
1380
  goto cleanup;
1340
1381
  } else {
1341
1382
  if (git_buf_joinpath(&base_path, backend->commonpath, git_buf_cstr(&relative_path)) < 0)
@@ -1355,7 +1396,7 @@ static int refdb_fs_backend__delete(
1355
1396
  const char *ref_name,
1356
1397
  const git_oid *old_id, const char *old_target)
1357
1398
  {
1358
- refdb_fs_backend *backend = (refdb_fs_backend *)_backend;
1399
+ refdb_fs_backend *backend = GIT_CONTAINER_OF(_backend, refdb_fs_backend, parent);
1359
1400
  git_filebuf file = GIT_FILEBUF_INIT;
1360
1401
  int error = 0;
1361
1402
 
@@ -1372,17 +1413,34 @@ static int refdb_fs_backend__delete(
1372
1413
  return refdb_fs_backend__delete_tail(_backend, &file, ref_name, old_id, old_target);
1373
1414
  }
1374
1415
 
1416
+ static int loose_delete(refdb_fs_backend *backend, const char *ref_name)
1417
+ {
1418
+ git_buf loose_path = GIT_BUF_INIT;
1419
+ int error = 0;
1420
+
1421
+ if (git_buf_joinpath(&loose_path, backend->commonpath, ref_name) < 0)
1422
+ return -1;
1423
+
1424
+ error = p_unlink(loose_path.ptr);
1425
+ if (error < 0 && errno == ENOENT)
1426
+ error = GIT_ENOTFOUND;
1427
+ else if (error != 0)
1428
+ error = -1;
1429
+
1430
+ git_buf_dispose(&loose_path);
1431
+
1432
+ return error;
1433
+ }
1434
+
1375
1435
  static int refdb_fs_backend__delete_tail(
1376
1436
  git_refdb_backend *_backend,
1377
1437
  git_filebuf *file,
1378
1438
  const char *ref_name,
1379
1439
  const git_oid *old_id, const char *old_target)
1380
1440
  {
1381
- refdb_fs_backend *backend = (refdb_fs_backend *)_backend;
1382
- git_buf loose_path = GIT_BUF_INIT;
1383
- size_t pack_pos;
1441
+ refdb_fs_backend *backend = GIT_CONTAINER_OF(_backend, refdb_fs_backend, parent);
1384
1442
  int error = 0, cmp = 0;
1385
- bool loose_deleted = 0;
1443
+ bool packed_deleted = 0;
1386
1444
 
1387
1445
  error = cmp_old_ref(&cmp, _backend, ref_name, old_id, old_target);
1388
1446
  if (error < 0)
@@ -1394,44 +1452,41 @@ static int refdb_fs_backend__delete_tail(
1394
1452
  goto cleanup;
1395
1453
  }
1396
1454
 
1397
- /* If a loose reference exists, remove it from the filesystem */
1398
- if (git_buf_joinpath(&loose_path, backend->commonpath, ref_name) < 0)
1399
- return -1;
1400
-
1401
-
1402
- error = p_unlink(loose_path.ptr);
1403
- if (error < 0 && errno == ENOENT)
1404
- error = 0;
1405
- else if (error < 0)
1455
+ /*
1456
+ * To ensure that an external observer will see either the current ref value
1457
+ * (because the loose ref still exists), or a missing ref (after the packed-file is
1458
+ * unlocked, there will be nothing left), we must ensure things happen in the
1459
+ * following order:
1460
+ *
1461
+ * - the packed-ref file is locked and loaded, as well as a loose one, if it exists
1462
+ * - we optimistically delete a packed ref, keeping track of whether it existed
1463
+ * - we delete the loose ref, note that we have its .lock
1464
+ * - the loose ref is "unlocked", then the packed-ref file is rewritten and unlocked
1465
+ * - we should prune the path components if a loose ref was deleted
1466
+ *
1467
+ * Note that, because our packed backend doesn't expose its filesystem lock,
1468
+ * we might not be able to guarantee that this is what actually happens (ie.
1469
+ * as our current code never write packed-refs.lock, nothing stops observers
1470
+ * from grabbing a "stale" value from there).
1471
+ */
1472
+ if ((error = packed_delete(backend, ref_name)) < 0 && error != GIT_ENOTFOUND)
1406
1473
  goto cleanup;
1407
- else if (error == 0)
1408
- loose_deleted = 1;
1409
1474
 
1410
- if ((error = packed_reload(backend)) < 0)
1411
- goto cleanup;
1475
+ if (error == 0)
1476
+ packed_deleted = 1;
1412
1477
 
1413
- /* If a packed reference exists, remove it from the packfile and repack */
1414
- if ((error = git_sortedcache_wlock(backend->refcache)) < 0)
1478
+ if ((error = loose_delete(backend, ref_name)) < 0 && error != GIT_ENOTFOUND)
1415
1479
  goto cleanup;
1416
1480
 
1417
- if (!(error = git_sortedcache_lookup_index(
1418
- &pack_pos, backend->refcache, ref_name)))
1419
- error = git_sortedcache_remove(backend->refcache, pack_pos);
1420
-
1421
- git_sortedcache_wunlock(backend->refcache);
1422
-
1423
1481
  if (error == GIT_ENOTFOUND) {
1424
- error = loose_deleted ? 0 : ref_error_notfound(ref_name);
1482
+ error = packed_deleted ? 0 : ref_error_notfound(ref_name);
1425
1483
  goto cleanup;
1426
1484
  }
1427
1485
 
1428
- error = packed_write(backend);
1429
-
1430
1486
  cleanup:
1431
- git_buf_dispose(&loose_path);
1432
1487
  git_filebuf_cleanup(file);
1433
- if (loose_deleted)
1434
- refdb_fs_backend__try_delete_empty_ref_hierarchie(backend, ref_name, false);
1488
+ if (error == 0)
1489
+ refdb_fs_backend__prune_refs(backend, ref_name, "");
1435
1490
  return error;
1436
1491
  }
1437
1492
 
@@ -1446,8 +1501,8 @@ static int refdb_fs_backend__rename(
1446
1501
  const git_signature *who,
1447
1502
  const char *message)
1448
1503
  {
1449
- refdb_fs_backend *backend = (refdb_fs_backend *)_backend;
1450
- git_reference *old, *new;
1504
+ refdb_fs_backend *backend = GIT_CONTAINER_OF(_backend, refdb_fs_backend, parent);
1505
+ git_reference *old, *new = NULL;
1451
1506
  git_filebuf file = GIT_FILEBUF_INIT;
1452
1507
  int error;
1453
1508
 
@@ -1463,7 +1518,7 @@ static int refdb_fs_backend__rename(
1463
1518
  return error;
1464
1519
  }
1465
1520
 
1466
- new = git_reference__set_name(old, new_name);
1521
+ new = git_reference__realloc(&old, new_name);
1467
1522
  if (!new) {
1468
1523
  git_reference_free(old);
1469
1524
  return -1;
@@ -1502,7 +1557,7 @@ static int refdb_fs_backend__rename(
1502
1557
  static int refdb_fs_backend__compress(git_refdb_backend *_backend)
1503
1558
  {
1504
1559
  int error;
1505
- refdb_fs_backend *backend = (refdb_fs_backend *)_backend;
1560
+ refdb_fs_backend *backend = GIT_CONTAINER_OF(_backend, refdb_fs_backend, parent);
1506
1561
 
1507
1562
  assert(backend);
1508
1563
 
@@ -1516,7 +1571,7 @@ static int refdb_fs_backend__compress(git_refdb_backend *_backend)
1516
1571
 
1517
1572
  static void refdb_fs_backend__free(git_refdb_backend *_backend)
1518
1573
  {
1519
- refdb_fs_backend *backend = (refdb_fs_backend *)_backend;
1574
+ refdb_fs_backend *backend = GIT_CONTAINER_OF(_backend, refdb_fs_backend, parent);
1520
1575
 
1521
1576
  assert(backend);
1522
1577
 
@@ -1597,70 +1652,57 @@ static int reflog_alloc(git_reflog **reflog, const char *name)
1597
1652
 
1598
1653
  static int reflog_parse(git_reflog *log, const char *buf, size_t buf_size)
1599
1654
  {
1600
- const char *ptr;
1601
- git_reflog_entry *entry;
1602
-
1603
- #define seek_forward(_increase) do { \
1604
- if (_increase >= buf_size) { \
1605
- git_error_set(GIT_ERROR_INVALID, "ran out of data while parsing reflog"); \
1606
- goto fail; \
1607
- } \
1608
- buf += _increase; \
1609
- buf_size -= _increase; \
1610
- } while (0)
1611
-
1612
- while (buf_size > GIT_REFLOG_SIZE_MIN) {
1613
- entry = git__calloc(1, sizeof(git_reflog_entry));
1614
- GIT_ERROR_CHECK_ALLOC(entry);
1655
+ git_parse_ctx parser = GIT_PARSE_CTX_INIT;
1615
1656
 
1616
- entry->committer = git__calloc(1, sizeof(git_signature));
1617
- GIT_ERROR_CHECK_ALLOC(entry->committer);
1657
+ if ((git_parse_ctx_init(&parser, buf, buf_size)) < 0)
1658
+ return -1;
1618
1659
 
1619
- if (git_oid_fromstrn(&entry->oid_old, buf, GIT_OID_HEXSZ) < 0)
1620
- goto fail;
1621
- seek_forward(GIT_OID_HEXSZ + 1);
1660
+ for (; parser.remain_len; git_parse_advance_line(&parser)) {
1661
+ git_reflog_entry *entry;
1662
+ const char *sig;
1663
+ char c;
1622
1664
 
1623
- if (git_oid_fromstrn(&entry->oid_cur, buf, GIT_OID_HEXSZ) < 0)
1624
- goto fail;
1625
- seek_forward(GIT_OID_HEXSZ + 1);
1665
+ entry = git__calloc(1, sizeof(*entry));
1666
+ GIT_ERROR_CHECK_ALLOC(entry);
1667
+ entry->committer = git__calloc(1, sizeof(*entry->committer));
1668
+ GIT_ERROR_CHECK_ALLOC(entry->committer);
1626
1669
 
1627
- ptr = buf;
1670
+ if (git_parse_advance_oid(&entry->oid_old, &parser) < 0 ||
1671
+ git_parse_advance_expected(&parser, " ", 1) < 0 ||
1672
+ git_parse_advance_oid(&entry->oid_cur, &parser) < 0)
1673
+ goto next;
1628
1674
 
1629
- /* Seek forward to the end of the signature. */
1630
- while (*buf && *buf != '\t' && *buf != '\n')
1631
- seek_forward(1);
1675
+ sig = parser.line;
1676
+ while (git_parse_peek(&c, &parser, 0) == 0 && c != '\t' && c != '\n')
1677
+ git_parse_advance_chars(&parser, 1);
1632
1678
 
1633
- if (git_signature__parse(entry->committer, &ptr, buf + 1, NULL, *buf) < 0)
1634
- goto fail;
1679
+ if (git_signature__parse(entry->committer, &sig, parser.line, NULL, 0) < 0)
1680
+ goto next;
1635
1681
 
1636
- if (*buf == '\t') {
1637
- /* We got a message. Read everything till we reach LF. */
1638
- seek_forward(1);
1639
- ptr = buf;
1682
+ if (c == '\t') {
1683
+ size_t len;
1684
+ git_parse_advance_chars(&parser, 1);
1640
1685
 
1641
- while (*buf && *buf != '\n')
1642
- seek_forward(1);
1686
+ len = parser.line_len;
1687
+ if (parser.line[len - 1] == '\n')
1688
+ len--;
1643
1689
 
1644
- entry->msg = git__strndup(ptr, buf - ptr);
1690
+ entry->msg = git__strndup(parser.line, len);
1645
1691
  GIT_ERROR_CHECK_ALLOC(entry->msg);
1646
- } else
1647
- entry->msg = NULL;
1692
+ }
1648
1693
 
1649
- while (*buf && *buf == '\n' && buf_size > 1)
1650
- seek_forward(1);
1694
+ if ((git_vector_insert(&log->entries, entry)) < 0) {
1695
+ git_reflog_entry__free(entry);
1696
+ return -1;
1697
+ }
1651
1698
 
1652
- if (git_vector_insert(&log->entries, entry) < 0)
1653
- goto fail;
1699
+ continue;
1700
+
1701
+ next:
1702
+ git_reflog_entry__free(entry);
1654
1703
  }
1655
1704
 
1656
1705
  return 0;
1657
-
1658
- #undef seek_forward
1659
-
1660
- fail:
1661
- git_reflog_entry__free(entry);
1662
-
1663
- return -1;
1664
1706
  }
1665
1707
 
1666
1708
  static int create_new_reflog_file(const char *filepath)
@@ -1694,7 +1736,7 @@ static int refdb_reflog_fs__ensure_log(git_refdb_backend *_backend, const char *
1694
1736
 
1695
1737
  assert(_backend && name);
1696
1738
 
1697
- backend = (refdb_fs_backend *) _backend;
1739
+ backend = GIT_CONTAINER_OF(_backend, refdb_fs_backend, parent);
1698
1740
  repo = backend->repo;
1699
1741
 
1700
1742
  if ((error = retrieve_reflog_path(&path, repo, name)) < 0)
@@ -1727,7 +1769,7 @@ static int refdb_reflog_fs__has_log(git_refdb_backend *_backend, const char *nam
1727
1769
 
1728
1770
  assert(_backend && name);
1729
1771
 
1730
- backend = (refdb_fs_backend *) _backend;
1772
+ backend = GIT_CONTAINER_OF(_backend, refdb_fs_backend, parent);
1731
1773
 
1732
1774
  return has_reflog(backend->repo, name);
1733
1775
  }
@@ -1743,7 +1785,7 @@ static int refdb_reflog_fs__read(git_reflog **out, git_refdb_backend *_backend,
1743
1785
 
1744
1786
  assert(out && _backend && name);
1745
1787
 
1746
- backend = (refdb_fs_backend *) _backend;
1788
+ backend = GIT_CONTAINER_OF(_backend, refdb_fs_backend, parent);
1747
1789
  repo = backend->repo;
1748
1790
 
1749
1791
  if (reflog_alloc(&log, name) < 0)
@@ -1802,8 +1844,15 @@ static int serialize_reflog_entry(
1802
1844
  git_buf_rtrim(buf);
1803
1845
 
1804
1846
  if (msg) {
1847
+ size_t i;
1848
+
1805
1849
  git_buf_putc(buf, '\t');
1806
1850
  git_buf_puts(buf, msg);
1851
+
1852
+ for (i = 0; i < buf->size - 2; i++)
1853
+ if (buf->ptr[i] == '\n')
1854
+ buf->ptr[i] = ' ';
1855
+ git_buf_rtrim(buf);
1807
1856
  }
1808
1857
 
1809
1858
  git_buf_putc(buf, '\n');
@@ -1853,7 +1902,7 @@ static int refdb_reflog_fs__write(git_refdb_backend *_backend, git_reflog *reflo
1853
1902
 
1854
1903
  assert(_backend && reflog);
1855
1904
 
1856
- backend = (refdb_fs_backend *) _backend;
1905
+ backend = GIT_CONTAINER_OF(_backend, refdb_fs_backend, parent);
1857
1906
 
1858
1907
  if ((error = lock_reflog(&fbuf, backend, reflog->ref_name)) < 0)
1859
1908
  return -1;
@@ -1894,7 +1943,7 @@ static int reflog_append(refdb_fs_backend *backend, const git_reference *ref, co
1894
1943
  !(old && new))
1895
1944
  return 0;
1896
1945
 
1897
- /* From here on is_symoblic also means that it's HEAD */
1946
+ /* From here on is_symbolic also means that it's HEAD */
1898
1947
 
1899
1948
  if (old) {
1900
1949
  git_oid_cpy(&old_id, old);
@@ -1975,7 +2024,7 @@ static int refdb_reflog_fs__rename(git_refdb_backend *_backend, const char *old_
1975
2024
 
1976
2025
  assert(_backend && old_name && new_name);
1977
2026
 
1978
- backend = (refdb_fs_backend *) _backend;
2027
+ backend = GIT_CONTAINER_OF(_backend, refdb_fs_backend, parent);
1979
2028
  repo = backend->repo;
1980
2029
 
1981
2030
  if ((error = git_reference__normalize_name(
@@ -2046,7 +2095,7 @@ cleanup:
2046
2095
 
2047
2096
  static int refdb_reflog_fs__delete(git_refdb_backend *_backend, const char *name)
2048
2097
  {
2049
- refdb_fs_backend *backend = (refdb_fs_backend *) _backend;
2098
+ refdb_fs_backend *backend = GIT_CONTAINER_OF(_backend, refdb_fs_backend, parent);
2050
2099
  git_buf path = GIT_BUF_INIT;
2051
2100
  int error;
2052
2101
 
@@ -2061,7 +2110,7 @@ static int refdb_reflog_fs__delete(git_refdb_backend *_backend, const char *name
2061
2110
  if ((error = p_unlink(path.ptr)) < 0)
2062
2111
  goto out;
2063
2112
 
2064
- refdb_fs_backend__try_delete_empty_ref_hierarchie(backend, name, true);
2113
+ refdb_fs_backend__prune_refs(backend, name, GIT_REFLOG_DIR);
2065
2114
 
2066
2115
  out:
2067
2116
  git_buf_dispose(&path);
@@ -2080,9 +2129,6 @@ int git_refdb_backend_fs(
2080
2129
  backend = git__calloc(1, sizeof(refdb_fs_backend));
2081
2130
  GIT_ERROR_CHECK_ALLOC(backend);
2082
2131
 
2083
- if (git_refdb_init_backend(&backend->parent, GIT_REFDB_BACKEND_VERSION) < 0)
2084
- goto fail;
2085
-
2086
2132
  backend->repo = repository;
2087
2133
 
2088
2134
  if (repository->gitdir) {
@@ -2107,15 +2153,15 @@ int git_refdb_backend_fs(
2107
2153
 
2108
2154
  git_buf_dispose(&gitpath);
2109
2155
 
2110
- if (!git_repository__cvar(&t, backend->repo, GIT_CVAR_IGNORECASE) && t) {
2156
+ if (!git_repository__configmap_lookup(&t, backend->repo, GIT_CONFIGMAP_IGNORECASE) && t) {
2111
2157
  backend->iterator_flags |= GIT_ITERATOR_IGNORE_CASE;
2112
2158
  backend->direach_flags |= GIT_PATH_DIR_IGNORE_CASE;
2113
2159
  }
2114
- if (!git_repository__cvar(&t, backend->repo, GIT_CVAR_PRECOMPOSE) && t) {
2160
+ if (!git_repository__configmap_lookup(&t, backend->repo, GIT_CONFIGMAP_PRECOMPOSE) && t) {
2115
2161
  backend->iterator_flags |= GIT_ITERATOR_PRECOMPOSE_UNICODE;
2116
2162
  backend->direach_flags |= GIT_PATH_DIR_PRECOMPOSE_UNICODE;
2117
2163
  }
2118
- if ((!git_repository__cvar(&t, backend->repo, GIT_CVAR_FSYNCOBJECTFILES) && t) ||
2164
+ if ((!git_repository__configmap_lookup(&t, backend->repo, GIT_CONFIGMAP_FSYNCOBJECTFILES) && t) ||
2119
2165
  git_repository__fsync_gitdir)
2120
2166
  backend->fsync = 1;
2121
2167
  backend->iterator_flags |= GIT_ITERATOR_DESCEND_SYMLINKS;