rugged 1.5.0.1 → 1.7.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (250) hide show
  1. checksums.yaml +4 -4
  2. data/ext/rugged/extconf.rb +2 -2
  3. data/ext/rugged/rugged_allocator.c +0 -54
  4. data/ext/rugged/rugged_blame.c +2 -0
  5. data/ext/rugged/rugged_blob.c +3 -0
  6. data/ext/rugged/rugged_commit.c +1 -0
  7. data/ext/rugged/rugged_config.c +2 -0
  8. data/ext/rugged/rugged_diff.c +1 -0
  9. data/ext/rugged/rugged_index.c +2 -0
  10. data/ext/rugged/rugged_patch.c +1 -0
  11. data/ext/rugged/rugged_rebase.c +1 -0
  12. data/ext/rugged/rugged_reference.c +1 -0
  13. data/ext/rugged/rugged_remote.c +1 -0
  14. data/ext/rugged/rugged_repo.c +5 -2
  15. data/ext/rugged/rugged_revwalk.c +5 -1
  16. data/ext/rugged/rugged_submodule.c +1 -0
  17. data/ext/rugged/rugged_tag.c +1 -0
  18. data/ext/rugged/rugged_tree.c +4 -0
  19. data/lib/rugged/index.rb +1 -1
  20. data/lib/rugged/tree.rb +1 -1
  21. data/lib/rugged/version.rb +1 -1
  22. data/vendor/libgit2/CMakeLists.txt +7 -8
  23. data/vendor/libgit2/COPYING +30 -0
  24. data/vendor/libgit2/cmake/CheckPrototypeDefinitionSafe.cmake +16 -0
  25. data/vendor/libgit2/cmake/ExperimentalFeatures.cmake +23 -0
  26. data/vendor/libgit2/cmake/SelectGSSAPI.cmake +3 -3
  27. data/vendor/libgit2/cmake/SelectHTTPSBackend.cmake +21 -2
  28. data/vendor/libgit2/cmake/SelectHashes.cmake +4 -0
  29. data/vendor/libgit2/cmake/SelectXdiff.cmake +9 -0
  30. data/vendor/libgit2/deps/ntlmclient/CMakeLists.txt +2 -0
  31. data/vendor/libgit2/deps/pcre/LICENCE +5 -5
  32. data/vendor/libgit2/deps/pcre/pcre.h +2 -2
  33. data/vendor/libgit2/deps/pcre/pcre_compile.c +6 -3
  34. data/vendor/libgit2/deps/pcre/pcre_exec.c +2 -2
  35. data/vendor/libgit2/deps/xdiff/CMakeLists.txt +28 -0
  36. data/vendor/libgit2/{src/libgit2 → deps}/xdiff/git-xdiff.h +4 -1
  37. data/vendor/libgit2/{src/libgit2 → deps}/xdiff/xdiffi.c +19 -18
  38. data/vendor/libgit2/{src/libgit2 → deps}/xdiff/xdiffi.h +2 -4
  39. data/vendor/libgit2/{src/libgit2 → deps}/xdiff/xemit.c +3 -3
  40. data/vendor/libgit2/{src/libgit2 → deps}/xdiff/xhistogram.c +7 -18
  41. data/vendor/libgit2/{src/libgit2 → deps}/xdiff/xmacros.h +18 -1
  42. data/vendor/libgit2/{src/libgit2 → deps}/xdiff/xmerge.c +24 -22
  43. data/vendor/libgit2/{src/libgit2 → deps}/xdiff/xpatience.c +21 -30
  44. data/vendor/libgit2/{src/libgit2 → deps}/xdiff/xprepare.c +13 -30
  45. data/vendor/libgit2/{src/libgit2 → deps}/xdiff/xutils.c +18 -1
  46. data/vendor/libgit2/{src/libgit2 → deps}/xdiff/xutils.h +2 -1
  47. data/vendor/libgit2/include/git2/common.h +38 -6
  48. data/vendor/libgit2/include/git2/deprecated.h +6 -0
  49. data/vendor/libgit2/include/git2/diff.h +42 -4
  50. data/vendor/libgit2/include/git2/errors.h +4 -2
  51. data/vendor/libgit2/include/git2/experimental.h +20 -0
  52. data/vendor/libgit2/include/git2/index.h +9 -0
  53. data/vendor/libgit2/include/git2/indexer.h +29 -0
  54. data/vendor/libgit2/include/git2/object.h +28 -2
  55. data/vendor/libgit2/include/git2/odb.h +58 -7
  56. data/vendor/libgit2/include/git2/odb_backend.h +106 -18
  57. data/vendor/libgit2/include/git2/oid.h +116 -16
  58. data/vendor/libgit2/include/git2/remote.h +18 -0
  59. data/vendor/libgit2/include/git2/repository.h +32 -3
  60. data/vendor/libgit2/include/git2/stash.h +60 -6
  61. data/vendor/libgit2/include/git2/strarray.h +0 -13
  62. data/vendor/libgit2/include/git2/sys/alloc.h +0 -34
  63. data/vendor/libgit2/include/git2/sys/commit_graph.h +12 -2
  64. data/vendor/libgit2/include/git2/sys/midx.h +5 -1
  65. data/vendor/libgit2/include/git2/sys/odb_backend.h +1 -1
  66. data/vendor/libgit2/include/git2/sys/stream.h +16 -2
  67. data/vendor/libgit2/include/git2/sys/transport.h +32 -2
  68. data/vendor/libgit2/include/git2/version.h +4 -4
  69. data/vendor/libgit2/include/git2/worktree.h +3 -1
  70. data/vendor/libgit2/include/git2.h +1 -0
  71. data/vendor/libgit2/src/CMakeLists.txt +34 -17
  72. data/vendor/libgit2/src/cli/CMakeLists.txt +5 -2
  73. data/vendor/libgit2/src/cli/cmd_clone.c +22 -6
  74. data/vendor/libgit2/src/cli/cmd_hash_object.c +27 -8
  75. data/vendor/libgit2/src/cli/opt.c +1 -1
  76. data/vendor/libgit2/src/cli/progress.c +9 -8
  77. data/vendor/libgit2/src/cli/progress.h +4 -4
  78. data/vendor/libgit2/src/libgit2/CMakeLists.txt +25 -34
  79. data/vendor/libgit2/src/libgit2/annotated_commit.c +2 -2
  80. data/vendor/libgit2/src/libgit2/annotated_commit.h +1 -1
  81. data/vendor/libgit2/src/libgit2/apply.c +4 -3
  82. data/vendor/libgit2/src/libgit2/attr_file.c +1 -1
  83. data/vendor/libgit2/src/libgit2/attrcache.c +1 -1
  84. data/vendor/libgit2/src/libgit2/blame.c +23 -14
  85. data/vendor/libgit2/src/libgit2/blame_git.c +0 -1
  86. data/vendor/libgit2/src/libgit2/blob.c +4 -2
  87. data/vendor/libgit2/src/libgit2/blob.h +2 -2
  88. data/vendor/libgit2/src/libgit2/branch.c +2 -2
  89. data/vendor/libgit2/src/libgit2/cherrypick.c +3 -3
  90. data/vendor/libgit2/src/libgit2/clone.c +34 -3
  91. data/vendor/libgit2/src/libgit2/commit.c +78 -21
  92. data/vendor/libgit2/src/libgit2/commit.h +25 -7
  93. data/vendor/libgit2/src/libgit2/commit_graph.c +129 -47
  94. data/vendor/libgit2/src/libgit2/commit_graph.h +23 -4
  95. data/vendor/libgit2/src/libgit2/commit_list.c +16 -5
  96. data/vendor/libgit2/src/libgit2/commit_list.h +1 -0
  97. data/vendor/libgit2/src/libgit2/config.c +6 -3
  98. data/vendor/libgit2/src/libgit2/config_file.c +16 -10
  99. data/vendor/libgit2/src/libgit2/describe.c +11 -8
  100. data/vendor/libgit2/src/libgit2/diff.c +19 -6
  101. data/vendor/libgit2/src/libgit2/diff.h +6 -6
  102. data/vendor/libgit2/src/libgit2/diff_file.c +16 -7
  103. data/vendor/libgit2/src/libgit2/diff_generate.c +37 -11
  104. data/vendor/libgit2/src/libgit2/diff_parse.c +20 -4
  105. data/vendor/libgit2/src/libgit2/diff_print.c +26 -7
  106. data/vendor/libgit2/src/libgit2/diff_tform.c +4 -0
  107. data/vendor/libgit2/src/libgit2/diff_xdiff.h +1 -1
  108. data/vendor/libgit2/src/libgit2/email.c +4 -3
  109. data/vendor/libgit2/src/libgit2/errors.c +73 -18
  110. data/vendor/libgit2/src/libgit2/experimental.h.in +13 -0
  111. data/vendor/libgit2/src/libgit2/fetch.c +38 -13
  112. data/vendor/libgit2/src/libgit2/fetch.h +0 -2
  113. data/vendor/libgit2/src/libgit2/fetchhead.c +11 -9
  114. data/vendor/libgit2/src/libgit2/grafts.c +272 -0
  115. data/vendor/libgit2/src/libgit2/grafts.h +36 -0
  116. data/vendor/libgit2/src/libgit2/ident.c +3 -3
  117. data/vendor/libgit2/src/libgit2/index.c +327 -123
  118. data/vendor/libgit2/src/libgit2/index.h +14 -1
  119. data/vendor/libgit2/src/libgit2/indexer.c +116 -46
  120. data/vendor/libgit2/src/libgit2/iterator.c +21 -4
  121. data/vendor/libgit2/src/libgit2/iterator.h +3 -0
  122. data/vendor/libgit2/src/libgit2/libgit2.c +58 -0
  123. data/vendor/libgit2/src/libgit2/merge.c +14 -9
  124. data/vendor/libgit2/src/libgit2/merge_file.c +0 -2
  125. data/vendor/libgit2/src/libgit2/midx.c +68 -38
  126. data/vendor/libgit2/src/libgit2/midx.h +13 -3
  127. data/vendor/libgit2/src/libgit2/mwindow.c +5 -2
  128. data/vendor/libgit2/src/libgit2/mwindow.h +4 -1
  129. data/vendor/libgit2/src/libgit2/notes.c +9 -8
  130. data/vendor/libgit2/src/libgit2/object.c +118 -29
  131. data/vendor/libgit2/src/libgit2/object.h +17 -2
  132. data/vendor/libgit2/src/libgit2/odb.c +224 -55
  133. data/vendor/libgit2/src/libgit2/odb.h +43 -4
  134. data/vendor/libgit2/src/libgit2/odb_loose.c +128 -70
  135. data/vendor/libgit2/src/libgit2/odb_pack.c +111 -46
  136. data/vendor/libgit2/src/libgit2/oid.c +141 -77
  137. data/vendor/libgit2/src/libgit2/oid.h +183 -9
  138. data/vendor/libgit2/src/libgit2/oidarray.c +49 -3
  139. data/vendor/libgit2/src/libgit2/oidarray.h +5 -1
  140. data/vendor/libgit2/src/libgit2/pack-objects.c +31 -13
  141. data/vendor/libgit2/src/libgit2/pack-objects.h +5 -2
  142. data/vendor/libgit2/src/libgit2/pack.c +93 -70
  143. data/vendor/libgit2/src/libgit2/pack.h +29 -15
  144. data/vendor/libgit2/src/libgit2/parse.c +8 -4
  145. data/vendor/libgit2/src/libgit2/parse.h +1 -1
  146. data/vendor/libgit2/src/libgit2/patch.h +7 -1
  147. data/vendor/libgit2/src/libgit2/patch_generate.c +24 -5
  148. data/vendor/libgit2/src/libgit2/patch_parse.c +16 -8
  149. data/vendor/libgit2/src/libgit2/push.c +13 -3
  150. data/vendor/libgit2/src/libgit2/reader.c +1 -1
  151. data/vendor/libgit2/src/libgit2/rebase.c +72 -83
  152. data/vendor/libgit2/src/libgit2/refdb_fs.c +92 -52
  153. data/vendor/libgit2/src/libgit2/reflog.c +7 -5
  154. data/vendor/libgit2/src/libgit2/reflog.h +1 -2
  155. data/vendor/libgit2/src/libgit2/refs.c +9 -0
  156. data/vendor/libgit2/src/libgit2/remote.c +47 -37
  157. data/vendor/libgit2/src/libgit2/remote.h +41 -0
  158. data/vendor/libgit2/src/libgit2/repository.c +784 -329
  159. data/vendor/libgit2/src/libgit2/repository.h +26 -2
  160. data/vendor/libgit2/src/libgit2/reset.c +2 -2
  161. data/vendor/libgit2/src/libgit2/revert.c +8 -11
  162. data/vendor/libgit2/src/libgit2/revparse.c +23 -7
  163. data/vendor/libgit2/src/libgit2/revwalk.c +31 -5
  164. data/vendor/libgit2/src/libgit2/stash.c +209 -33
  165. data/vendor/libgit2/src/libgit2/strarray.c +1 -0
  166. data/vendor/libgit2/src/libgit2/strarray.h +25 -0
  167. data/vendor/libgit2/src/libgit2/streams/mbedtls.c +0 -1
  168. data/vendor/libgit2/src/libgit2/streams/openssl.c +9 -17
  169. data/vendor/libgit2/src/libgit2/streams/openssl_dynamic.c +7 -3
  170. data/vendor/libgit2/src/libgit2/streams/schannel.c +715 -0
  171. data/vendor/libgit2/src/libgit2/streams/schannel.h +28 -0
  172. data/vendor/libgit2/src/libgit2/streams/socket.c +240 -51
  173. data/vendor/libgit2/src/libgit2/streams/socket.h +3 -1
  174. data/vendor/libgit2/src/libgit2/streams/stransport.c +40 -12
  175. data/vendor/libgit2/src/libgit2/streams/tls.c +5 -0
  176. data/vendor/libgit2/src/libgit2/submodule.c +6 -2
  177. data/vendor/libgit2/src/libgit2/submodule.h +3 -3
  178. data/vendor/libgit2/src/libgit2/sysdir.c +294 -7
  179. data/vendor/libgit2/src/libgit2/sysdir.h +41 -9
  180. data/vendor/libgit2/src/libgit2/tag.c +29 -10
  181. data/vendor/libgit2/src/libgit2/tag.h +2 -2
  182. data/vendor/libgit2/src/libgit2/threadstate.c +15 -2
  183. data/vendor/libgit2/src/libgit2/threadstate.h +1 -3
  184. data/vendor/libgit2/src/libgit2/transports/auth.h +1 -2
  185. data/vendor/libgit2/src/libgit2/transports/{auth_negotiate.c → auth_gssapi.c} +32 -32
  186. data/vendor/libgit2/src/libgit2/transports/auth_negotiate.h +1 -1
  187. data/vendor/libgit2/src/libgit2/transports/auth_ntlm.h +1 -1
  188. data/vendor/libgit2/src/libgit2/transports/{auth_ntlm.c → auth_ntlmclient.c} +12 -12
  189. data/vendor/libgit2/src/libgit2/transports/auth_sspi.c +341 -0
  190. data/vendor/libgit2/src/libgit2/transports/git.c +7 -8
  191. data/vendor/libgit2/src/libgit2/transports/http.c +15 -9
  192. data/vendor/libgit2/src/libgit2/transports/httpclient.c +14 -0
  193. data/vendor/libgit2/src/libgit2/transports/httpclient.h +10 -0
  194. data/vendor/libgit2/src/libgit2/transports/local.c +27 -4
  195. data/vendor/libgit2/src/libgit2/transports/smart.c +68 -27
  196. data/vendor/libgit2/src/libgit2/transports/smart.h +33 -9
  197. data/vendor/libgit2/src/libgit2/transports/smart_pkt.c +281 -49
  198. data/vendor/libgit2/src/libgit2/transports/smart_protocol.c +192 -55
  199. data/vendor/libgit2/src/libgit2/transports/ssh.c +334 -102
  200. data/vendor/libgit2/src/libgit2/transports/winhttp.c +22 -18
  201. data/vendor/libgit2/src/libgit2/tree-cache.c +26 -16
  202. data/vendor/libgit2/src/libgit2/tree-cache.h +5 -3
  203. data/vendor/libgit2/src/libgit2/tree.c +23 -17
  204. data/vendor/libgit2/src/libgit2/tree.h +2 -2
  205. data/vendor/libgit2/src/libgit2/worktree.c +30 -10
  206. data/vendor/libgit2/src/util/CMakeLists.txt +6 -1
  207. data/vendor/libgit2/src/util/alloc.c +65 -6
  208. data/vendor/libgit2/src/util/alloc.h +34 -9
  209. data/vendor/libgit2/src/util/allocators/failalloc.c +0 -60
  210. data/vendor/libgit2/src/util/allocators/failalloc.h +0 -6
  211. data/vendor/libgit2/src/util/allocators/stdalloc.c +2 -105
  212. data/vendor/libgit2/src/util/allocators/win32_leakcheck.c +0 -68
  213. data/vendor/libgit2/src/util/array.h +6 -1
  214. data/vendor/libgit2/src/util/cc-compat.h +2 -0
  215. data/vendor/libgit2/src/util/filebuf.c +6 -1
  216. data/vendor/libgit2/src/util/filebuf.h +19 -6
  217. data/vendor/libgit2/src/util/fs_path.c +2 -2
  218. data/vendor/libgit2/src/util/futils.c +8 -8
  219. data/vendor/libgit2/src/{features.h.in → util/git2_features.h.in} +9 -3
  220. data/vendor/libgit2/src/util/git2_util.h +2 -2
  221. data/vendor/libgit2/src/util/hash/openssl.c +4 -3
  222. data/vendor/libgit2/src/util/hash/rfc6234/sha.h +0 -112
  223. data/vendor/libgit2/src/util/hash.h +13 -0
  224. data/vendor/libgit2/src/util/net.c +492 -87
  225. data/vendor/libgit2/src/util/net.h +32 -0
  226. data/vendor/libgit2/src/util/posix.c +54 -0
  227. data/vendor/libgit2/src/util/posix.h +24 -0
  228. data/vendor/libgit2/src/util/rand.c +10 -4
  229. data/vendor/libgit2/src/util/regexp.c +3 -3
  230. data/vendor/libgit2/src/util/staticstr.h +66 -0
  231. data/vendor/libgit2/src/util/thread.h +20 -19
  232. data/vendor/libgit2/src/util/util.c +15 -10
  233. data/vendor/libgit2/src/util/util.h +25 -16
  234. data/vendor/libgit2/src/util/win32/error.c +1 -1
  235. data/vendor/libgit2/src/util/win32/path_w32.c +8 -8
  236. data/vendor/libgit2/src/util/win32/posix_w32.c +1 -1
  237. data/vendor/libgit2/src/util/win32/utf-conv.c +73 -75
  238. data/vendor/libgit2/src/util/win32/utf-conv.h +81 -14
  239. data/vendor/libgit2/src/util/win32/w32_util.c +1 -1
  240. metadata +34 -26
  241. data/vendor/libgit2/cmake/SelectWinHTTP.cmake +0 -17
  242. data/vendor/libgit2/src/libgit2/netops.c +0 -124
  243. data/vendor/libgit2/src/libgit2/netops.h +0 -68
  244. data/vendor/libgit2/src/util/win32/findfile.c +0 -286
  245. data/vendor/libgit2/src/util/win32/findfile.h +0 -22
  246. /data/vendor/libgit2/{src/libgit2 → deps}/xdiff/xdiff.h +0 -0
  247. /data/vendor/libgit2/{src/libgit2 → deps}/xdiff/xemit.h +0 -0
  248. /data/vendor/libgit2/{src/libgit2 → deps}/xdiff/xinclude.h +0 -0
  249. /data/vendor/libgit2/{src/libgit2 → deps}/xdiff/xprepare.h +0 -0
  250. /data/vendor/libgit2/{src/libgit2 → deps}/xdiff/xtypes.h +0 -0
@@ -16,32 +16,51 @@
16
16
  * New error handling
17
17
  ********************************************/
18
18
 
19
- static git_error g_git_oom_error = {
19
+ static git_error oom_error = {
20
20
  "Out of memory",
21
21
  GIT_ERROR_NOMEMORY
22
22
  };
23
23
 
24
- static git_error g_git_uninitialized_error = {
24
+ static git_error uninitialized_error = {
25
25
  "libgit2 has not been initialized; you must call git_libgit2_init",
26
26
  GIT_ERROR_INVALID
27
27
  };
28
28
 
29
+ static git_error tlsdata_error = {
30
+ "thread-local data initialization failure",
31
+ GIT_ERROR
32
+ };
33
+
29
34
  static void set_error_from_buffer(int error_class)
30
35
  {
31
- git_error *error = &GIT_THREADSTATE->error_t;
32
- git_str *buf = &GIT_THREADSTATE->error_buf;
36
+ git_threadstate *threadstate = git_threadstate_get();
37
+ git_error *error;
38
+ git_str *buf;
39
+
40
+ if (!threadstate)
41
+ return;
42
+
43
+ error = &threadstate->error_t;
44
+ buf = &threadstate->error_buf;
33
45
 
34
46
  error->message = buf->ptr;
35
47
  error->klass = error_class;
36
48
 
37
- GIT_THREADSTATE->last_error = error;
49
+ threadstate->last_error = error;
38
50
  }
39
51
 
40
52
  static void set_error(int error_class, char *string)
41
53
  {
42
- git_str *buf = &GIT_THREADSTATE->error_buf;
54
+ git_threadstate *threadstate = git_threadstate_get();
55
+ git_str *buf;
56
+
57
+ if (!threadstate)
58
+ return;
59
+
60
+ buf = &threadstate->error_buf;
43
61
 
44
62
  git_str_clear(buf);
63
+
45
64
  if (string) {
46
65
  git_str_puts(buf, string);
47
66
  git__free(string);
@@ -52,7 +71,12 @@ static void set_error(int error_class, char *string)
52
71
 
53
72
  void git_error_set_oom(void)
54
73
  {
55
- GIT_THREADSTATE->last_error = &g_git_oom_error;
74
+ git_threadstate *threadstate = git_threadstate_get();
75
+
76
+ if (!threadstate)
77
+ return;
78
+
79
+ threadstate->last_error = &oom_error;
56
80
  }
57
81
 
58
82
  void git_error_set(int error_class, const char *fmt, ...)
@@ -69,10 +93,18 @@ void git_error_vset(int error_class, const char *fmt, va_list ap)
69
93
  #ifdef GIT_WIN32
70
94
  DWORD win32_error_code = (error_class == GIT_ERROR_OS) ? GetLastError() : 0;
71
95
  #endif
96
+
97
+ git_threadstate *threadstate = git_threadstate_get();
72
98
  int error_code = (error_class == GIT_ERROR_OS) ? errno : 0;
73
- git_str *buf = &GIT_THREADSTATE->error_buf;
99
+ git_str *buf;
100
+
101
+ if (!threadstate)
102
+ return;
103
+
104
+ buf = &threadstate->error_buf;
74
105
 
75
106
  git_str_clear(buf);
107
+
76
108
  if (fmt) {
77
109
  git_str_vprintf(buf, fmt, ap);
78
110
  if (error_class == GIT_ERROR_OS)
@@ -81,7 +113,7 @@ void git_error_vset(int error_class, const char *fmt, va_list ap)
81
113
 
82
114
  if (error_class == GIT_ERROR_OS) {
83
115
  #ifdef GIT_WIN32
84
- char * win32_error = git_win32_get_error_message(win32_error_code);
116
+ char *win32_error = git_win32_get_error_message(win32_error_code);
85
117
  if (win32_error) {
86
118
  git_str_puts(buf, win32_error);
87
119
  git__free(win32_error);
@@ -103,10 +135,16 @@ void git_error_vset(int error_class, const char *fmt, va_list ap)
103
135
 
104
136
  int git_error_set_str(int error_class, const char *string)
105
137
  {
106
- git_str *buf = &GIT_THREADSTATE->error_buf;
138
+ git_threadstate *threadstate = git_threadstate_get();
139
+ git_str *buf;
107
140
 
108
141
  GIT_ASSERT_ARG(string);
109
142
 
143
+ if (!threadstate)
144
+ return -1;
145
+
146
+ buf = &threadstate->error_buf;
147
+
110
148
  git_str_clear(buf);
111
149
  git_str_puts(buf, string);
112
150
 
@@ -119,9 +157,14 @@ int git_error_set_str(int error_class, const char *string)
119
157
 
120
158
  void git_error_clear(void)
121
159
  {
122
- if (GIT_THREADSTATE->last_error != NULL) {
160
+ git_threadstate *threadstate = git_threadstate_get();
161
+
162
+ if (!threadstate)
163
+ return;
164
+
165
+ if (threadstate->last_error != NULL) {
123
166
  set_error(0, NULL);
124
- GIT_THREADSTATE->last_error = NULL;
167
+ threadstate->last_error = NULL;
125
168
  }
126
169
 
127
170
  errno = 0;
@@ -132,17 +175,29 @@ void git_error_clear(void)
132
175
 
133
176
  const git_error *git_error_last(void)
134
177
  {
178
+ git_threadstate *threadstate;
179
+
135
180
  /* If the library is not initialized, return a static error. */
136
181
  if (!git_libgit2_init_count())
137
- return &g_git_uninitialized_error;
182
+ return &uninitialized_error;
183
+
184
+ if ((threadstate = git_threadstate_get()) == NULL)
185
+ return &tlsdata_error;
138
186
 
139
- return GIT_THREADSTATE->last_error;
187
+ return threadstate->last_error;
140
188
  }
141
189
 
142
190
  int git_error_state_capture(git_error_state *state, int error_code)
143
191
  {
144
- git_error *error = GIT_THREADSTATE->last_error;
145
- git_str *error_buf = &GIT_THREADSTATE->error_buf;
192
+ git_threadstate *threadstate = git_threadstate_get();
193
+ git_error *error;
194
+ git_str *error_buf;
195
+
196
+ if (!threadstate)
197
+ return -1;
198
+
199
+ error = threadstate->last_error;
200
+ error_buf = &threadstate->error_buf;
146
201
 
147
202
  memset(state, 0, sizeof(git_error_state));
148
203
 
@@ -150,13 +205,13 @@ int git_error_state_capture(git_error_state *state, int error_code)
150
205
  return 0;
151
206
 
152
207
  state->error_code = error_code;
153
- state->oom = (error == &g_git_oom_error);
208
+ state->oom = (error == &oom_error);
154
209
 
155
210
  if (error) {
156
211
  state->error_msg.klass = error->klass;
157
212
 
158
213
  if (state->oom)
159
- state->error_msg.message = g_git_oom_error.message;
214
+ state->error_msg.message = oom_error.message;
160
215
  else
161
216
  state->error_msg.message = git_str_detach(error_buf);
162
217
  }
@@ -0,0 +1,13 @@
1
+ /*
2
+ * Copyright (C) the libgit2 contributors. All rights reserved.
3
+ *
4
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
5
+ * a Linking Exception. For full terms see the included COPYING file.
6
+ */
7
+
8
+ #ifndef INCLUDE_experimental_h__
9
+ #define INCLUDE_experimental_h__
10
+
11
+ #cmakedefine GIT_EXPERIMENTAL_SHA256 1
12
+
13
+ #endif
@@ -13,12 +13,13 @@
13
13
  #include "git2/transport.h"
14
14
  #include "git2/sys/remote.h"
15
15
 
16
+ #include "oid.h"
16
17
  #include "remote.h"
17
18
  #include "refspec.h"
18
19
  #include "pack.h"
19
- #include "netops.h"
20
20
  #include "repository.h"
21
21
  #include "refs.h"
22
+ #include "transports/smart.h"
22
23
 
23
24
  static int maybe_want(git_remote *remote, git_remote_head *head, git_refspec *tagspec, git_remote_autotag_option_t tagopt)
24
25
  {
@@ -58,8 +59,10 @@ static int mark_local(git_remote *remote)
58
59
  return -1;
59
60
 
60
61
  git_vector_foreach(&remote->refs, i, head) {
61
- /* If we have the object, mark it so we don't ask for it */
62
- if (git_odb_exists(odb, &head->oid))
62
+ /* If we have the object, mark it so we don't ask for it.
63
+ However if we are unshallowing, we need to ask for it
64
+ even though the head exists locally. */
65
+ if (remote->nego.depth != INT_MAX && git_odb_exists(odb, &head->oid))
63
66
  head->local = 1;
64
67
  else
65
68
  remote->need_pack = 1;
@@ -75,7 +78,7 @@ static int maybe_want_oid(git_remote *remote, git_refspec *spec)
75
78
  oid_head = git__calloc(1, sizeof(git_remote_head));
76
79
  GIT_ERROR_CHECK_ALLOC(oid_head);
77
80
 
78
- git_oid_fromstr(&oid_head->oid, spec->src);
81
+ git_oid__fromstr(&oid_head->oid, spec->src, remote->repo->oid_type);
79
82
 
80
83
  if (spec->dst) {
81
84
  oid_head->name = git__strdup(spec->dst);
@@ -94,7 +97,6 @@ static int filter_wants(git_remote *remote, const git_fetch_options *opts)
94
97
  git_remote_head **heads;
95
98
  git_refspec tagspec, head, *spec;
96
99
  int error = 0;
97
- git_odb *odb;
98
100
  size_t i, heads_len;
99
101
  unsigned int remote_caps;
100
102
  unsigned int oid_mask = GIT_REMOTE_CAPABILITY_TIP_OID |
@@ -125,9 +127,6 @@ static int filter_wants(git_remote *remote, const git_fetch_options *opts)
125
127
  goto cleanup;
126
128
  }
127
129
 
128
- if ((error = git_repository_odb__weakptr(&odb, remote->repo)) < 0)
129
- goto cleanup;
130
-
131
130
  if ((error = git_remote_ls((const git_remote_head ***)&heads, &heads_len, remote)) < 0 ||
132
131
  (error = git_remote_capabilities(&remote_caps, remote)) < 0)
133
132
  goto cleanup;
@@ -140,7 +139,7 @@ static int filter_wants(git_remote *remote, const git_fetch_options *opts)
140
139
 
141
140
  /* Handle explicitly specified OID specs */
142
141
  git_vector_foreach(&remote->active_refspecs, i, spec) {
143
- if (!git_oid__is_hexstr(spec->src))
142
+ if (!git_oid__is_hexstr(spec->src, remote->repo->oid_type))
144
143
  continue;
145
144
 
146
145
  if (!(remote_caps & oid_mask)) {
@@ -169,9 +168,15 @@ cleanup:
169
168
  int git_fetch_negotiate(git_remote *remote, const git_fetch_options *opts)
170
169
  {
171
170
  git_transport *t = remote->transport;
171
+ int error;
172
172
 
173
173
  remote->need_pack = 0;
174
174
 
175
+ if (opts) {
176
+ GIT_ASSERT_ARG(opts->depth >= 0);
177
+ remote->nego.depth = opts->depth;
178
+ }
179
+
175
180
  if (filter_wants(remote, opts) < 0)
176
181
  return -1;
177
182
 
@@ -183,20 +188,40 @@ int git_fetch_negotiate(git_remote *remote, const git_fetch_options *opts)
183
188
  * Now we have everything set up so we can start tell the
184
189
  * server what we want and what we have.
185
190
  */
186
- return t->negotiate_fetch(t,
191
+ remote->nego.refs = (const git_remote_head * const *)remote->refs.contents;
192
+ remote->nego.refs_len = remote->refs.length;
193
+
194
+ if (git_repository__shallow_roots(&remote->nego.shallow_roots,
195
+ &remote->nego.shallow_roots_len,
196
+ remote->repo) < 0)
197
+ return -1;
198
+
199
+ error = t->negotiate_fetch(t,
187
200
  remote->repo,
188
- (const git_remote_head * const *)remote->refs.contents,
189
- remote->refs.length);
201
+ &remote->nego);
202
+
203
+ git__free(remote->nego.shallow_roots);
204
+
205
+ return error;
190
206
  }
191
207
 
192
208
  int git_fetch_download_pack(git_remote *remote)
193
209
  {
210
+ git_oidarray shallow_roots = { NULL };
194
211
  git_transport *t = remote->transport;
212
+ int error;
195
213
 
196
214
  if (!remote->need_pack)
197
215
  return 0;
198
216
 
199
- return t->download_pack(t, remote->repo, &remote->stats);
217
+ if ((error = t->download_pack(t, remote->repo, &remote->stats)) != 0 ||
218
+ (error = t->shallow_roots(&shallow_roots, t)) != 0)
219
+ return error;
220
+
221
+ error = git_repository__shallow_roots_write(remote->repo, &shallow_roots);
222
+
223
+ git_oidarray_dispose(&shallow_roots);
224
+ return error;
200
225
  }
201
226
 
202
227
  int git_fetch_options_init(git_fetch_options *opts, unsigned int version)
@@ -11,8 +11,6 @@
11
11
 
12
12
  #include "git2/remote.h"
13
13
 
14
- #include "netops.h"
15
-
16
14
  int git_fetch_negotiate(git_remote *remote, const git_fetch_options *opts);
17
15
 
18
16
  int git_fetch_download_pack(git_remote *remote);
@@ -105,15 +105,14 @@ static int fetchhead_ref_write(
105
105
  git_filebuf *file,
106
106
  git_fetchhead_ref *fetchhead_ref)
107
107
  {
108
- char oid[GIT_OID_HEXSZ + 1];
108
+ char oid[GIT_OID_MAX_HEXSIZE + 1];
109
109
  const char *type, *name;
110
110
  int head = 0;
111
111
 
112
112
  GIT_ASSERT_ARG(file);
113
113
  GIT_ASSERT_ARG(fetchhead_ref);
114
114
 
115
- git_oid_fmt(oid, &fetchhead_ref->oid);
116
- oid[GIT_OID_HEXSZ] = '\0';
115
+ git_oid_tostr(oid, GIT_OID_MAX_HEXSIZE + 1, &fetchhead_ref->oid);
117
116
 
118
117
  if (git__prefixcmp(fetchhead_ref->ref_name, GIT_REFS_HEADS_DIR) == 0) {
119
118
  type = "branch ";
@@ -174,7 +173,8 @@ static int fetchhead_ref_parse(
174
173
  git_str *ref_name,
175
174
  const char **remote_url,
176
175
  char *line,
177
- size_t line_num)
176
+ size_t line_num,
177
+ git_oid_t oid_type)
178
178
  {
179
179
  char *oid_str, *is_merge_str, *desc, *name = NULL;
180
180
  const char *type = NULL;
@@ -196,13 +196,13 @@ static int fetchhead_ref_parse(
196
196
  *is_merge = 1;
197
197
  }
198
198
 
199
- if (strlen(oid_str) != GIT_OID_HEXSZ) {
199
+ if (strlen(oid_str) != git_oid_hexsize(oid_type)) {
200
200
  git_error_set(GIT_ERROR_FETCHHEAD,
201
201
  "invalid object ID in FETCH_HEAD line %"PRIuZ, line_num);
202
202
  return -1;
203
203
  }
204
204
 
205
- if (git_oid_fromstr(oid, oid_str) < 0) {
205
+ if (git_oid__fromstr(oid, oid_str, oid_type) < 0) {
206
206
  const git_error *oid_err = git_error_last();
207
207
  const char *err_msg = oid_err ? oid_err->message : "invalid object ID";
208
208
 
@@ -269,7 +269,8 @@ static int fetchhead_ref_parse(
269
269
  return error;
270
270
  }
271
271
 
272
- int git_repository_fetchhead_foreach(git_repository *repo,
272
+ int git_repository_fetchhead_foreach(
273
+ git_repository *repo,
273
274
  git_repository_fetchhead_foreach_cb cb,
274
275
  void *payload)
275
276
  {
@@ -296,8 +297,9 @@ int git_repository_fetchhead_foreach(git_repository *repo,
296
297
  while ((line = git__strsep(&buffer, "\n")) != NULL) {
297
298
  ++line_num;
298
299
 
299
- if ((error = fetchhead_ref_parse(
300
- &oid, &is_merge, &name, &remote_url, line, line_num)) < 0)
300
+ if ((error = fetchhead_ref_parse(&oid, &is_merge, &name,
301
+ &remote_url, line, line_num,
302
+ repo->oid_type)) < 0)
301
303
  goto done;
302
304
 
303
305
  if (git_str_len(&name) > 0)
@@ -0,0 +1,272 @@
1
+ /*
2
+ * Copyright (C) the libgit2 contributors. All rights reserved.
3
+ *
4
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
5
+ * a Linking Exception. For full terms see the included COPYING file.
6
+ */
7
+
8
+ #include "grafts.h"
9
+
10
+ #include "futils.h"
11
+ #include "oid.h"
12
+ #include "oidarray.h"
13
+ #include "parse.h"
14
+
15
+ struct git_grafts {
16
+ /* Map of `git_commit_graft`s */
17
+ git_oidmap *commits;
18
+
19
+ /* Type of object IDs */
20
+ git_oid_t oid_type;
21
+
22
+ /* File backing the graft. NULL if it's an in-memory graft */
23
+ char *path;
24
+ unsigned char path_checksum[GIT_HASH_SHA256_SIZE];
25
+ };
26
+
27
+ int git_grafts_new(git_grafts **out, git_oid_t oid_type)
28
+ {
29
+ git_grafts *grafts;
30
+
31
+ GIT_ASSERT_ARG(out && oid_type);
32
+
33
+ grafts = git__calloc(1, sizeof(*grafts));
34
+ GIT_ERROR_CHECK_ALLOC(grafts);
35
+
36
+ if ((git_oidmap_new(&grafts->commits)) < 0) {
37
+ git__free(grafts);
38
+ return -1;
39
+ }
40
+
41
+ grafts->oid_type = oid_type;
42
+
43
+ *out = grafts;
44
+ return 0;
45
+ }
46
+
47
+ int git_grafts_open(
48
+ git_grafts **out,
49
+ const char *path,
50
+ git_oid_t oid_type)
51
+ {
52
+ git_grafts *grafts = NULL;
53
+ int error;
54
+
55
+ GIT_ASSERT_ARG(out && path && oid_type);
56
+
57
+ if ((error = git_grafts_new(&grafts, oid_type)) < 0)
58
+ goto error;
59
+
60
+ grafts->path = git__strdup(path);
61
+ GIT_ERROR_CHECK_ALLOC(grafts->path);
62
+
63
+ if ((error = git_grafts_refresh(grafts)) < 0)
64
+ goto error;
65
+
66
+ *out = grafts;
67
+
68
+ error:
69
+ if (error < 0)
70
+ git_grafts_free(grafts);
71
+
72
+ return error;
73
+ }
74
+
75
+ int git_grafts_open_or_refresh(
76
+ git_grafts **out,
77
+ const char *path,
78
+ git_oid_t oid_type)
79
+ {
80
+ GIT_ASSERT_ARG(out && path && oid_type);
81
+
82
+ return *out ? git_grafts_refresh(*out) : git_grafts_open(out, path, oid_type);
83
+ }
84
+
85
+ void git_grafts_free(git_grafts *grafts)
86
+ {
87
+ if (!grafts)
88
+ return;
89
+ git__free(grafts->path);
90
+ git_grafts_clear(grafts);
91
+ git_oidmap_free(grafts->commits);
92
+ git__free(grafts);
93
+ }
94
+
95
+ void git_grafts_clear(git_grafts *grafts)
96
+ {
97
+ git_commit_graft *graft;
98
+
99
+ if (!grafts)
100
+ return;
101
+
102
+ git_oidmap_foreach_value(grafts->commits, graft, {
103
+ git__free(graft->parents.ptr);
104
+ git__free(graft);
105
+ });
106
+
107
+ git_oidmap_clear(grafts->commits);
108
+ }
109
+
110
+ int git_grafts_refresh(git_grafts *grafts)
111
+ {
112
+ git_str contents = GIT_STR_INIT;
113
+ int error, updated = 0;
114
+
115
+ GIT_ASSERT_ARG(grafts);
116
+
117
+ if (!grafts->path)
118
+ return 0;
119
+
120
+ if ((error = git_futils_readbuffer_updated(&contents, grafts->path,
121
+ grafts->path_checksum, &updated)) < 0) {
122
+
123
+ if (error == GIT_ENOTFOUND) {
124
+ git_grafts_clear(grafts);
125
+ error = 0;
126
+ }
127
+
128
+ goto cleanup;
129
+ }
130
+
131
+ if (!updated) {
132
+ goto cleanup;
133
+ }
134
+
135
+ if ((error = git_grafts_parse(grafts, contents.ptr, contents.size)) < 0)
136
+ goto cleanup;
137
+
138
+ cleanup:
139
+ git_str_dispose(&contents);
140
+ return error;
141
+ }
142
+
143
+ int git_grafts_parse(git_grafts *grafts, const char *buf, size_t len)
144
+ {
145
+ git_array_oid_t parents = GIT_ARRAY_INIT;
146
+ git_parse_ctx parser;
147
+ int error;
148
+
149
+ git_grafts_clear(grafts);
150
+
151
+ if ((error = git_parse_ctx_init(&parser, buf, len)) < 0)
152
+ goto error;
153
+
154
+ for (; parser.remain_len; git_parse_advance_line(&parser)) {
155
+ git_oid graft_oid;
156
+
157
+ if ((error = git_parse_advance_oid(&graft_oid, &parser, grafts->oid_type)) < 0) {
158
+ git_error_set(GIT_ERROR_GRAFTS, "invalid graft OID at line %" PRIuZ, parser.line_num);
159
+ goto error;
160
+ }
161
+
162
+ while (parser.line_len && git_parse_advance_expected(&parser, "\n", 1) != 0) {
163
+ git_oid *id = git_array_alloc(parents);
164
+ GIT_ERROR_CHECK_ALLOC(id);
165
+
166
+ if ((error = git_parse_advance_expected(&parser, " ", 1)) < 0 ||
167
+ (error = git_parse_advance_oid(id, &parser, grafts->oid_type)) < 0) {
168
+ git_error_set(GIT_ERROR_GRAFTS, "invalid parent OID at line %" PRIuZ, parser.line_num);
169
+ goto error;
170
+ }
171
+ }
172
+
173
+ if ((error = git_grafts_add(grafts, &graft_oid, parents)) < 0)
174
+ goto error;
175
+
176
+ git_array_clear(parents);
177
+ }
178
+
179
+ error:
180
+ git_array_clear(parents);
181
+ return error;
182
+ }
183
+
184
+ int git_grafts_add(git_grafts *grafts, const git_oid *oid, git_array_oid_t parents)
185
+ {
186
+ git_commit_graft *graft;
187
+ git_oid *parent_oid;
188
+ int error;
189
+ size_t i;
190
+
191
+ GIT_ASSERT_ARG(grafts && oid);
192
+
193
+ graft = git__calloc(1, sizeof(*graft));
194
+ GIT_ERROR_CHECK_ALLOC(graft);
195
+
196
+ git_array_init_to_size(graft->parents, git_array_size(parents));
197
+ git_array_foreach(parents, i, parent_oid) {
198
+ git_oid *id = git_array_alloc(graft->parents);
199
+ GIT_ERROR_CHECK_ALLOC(id);
200
+
201
+ git_oid_cpy(id, parent_oid);
202
+ }
203
+ git_oid_cpy(&graft->oid, oid);
204
+
205
+ if ((error = git_grafts_remove(grafts, &graft->oid)) < 0 && error != GIT_ENOTFOUND)
206
+ goto cleanup;
207
+
208
+ if ((error = git_oidmap_set(grafts->commits, &graft->oid, graft)) < 0)
209
+ goto cleanup;
210
+
211
+ return 0;
212
+
213
+ cleanup:
214
+ git_array_clear(graft->parents);
215
+ git__free(graft);
216
+ return error;
217
+ }
218
+
219
+ int git_grafts_remove(git_grafts *grafts, const git_oid *oid)
220
+ {
221
+ git_commit_graft *graft;
222
+ int error;
223
+
224
+ GIT_ASSERT_ARG(grafts && oid);
225
+
226
+ if ((graft = git_oidmap_get(grafts->commits, oid)) == NULL)
227
+ return GIT_ENOTFOUND;
228
+
229
+ if ((error = git_oidmap_delete(grafts->commits, oid)) < 0)
230
+ return error;
231
+
232
+ git__free(graft->parents.ptr);
233
+ git__free(graft);
234
+
235
+ return 0;
236
+ }
237
+
238
+ int git_grafts_get(git_commit_graft **out, git_grafts *grafts, const git_oid *oid)
239
+ {
240
+ GIT_ASSERT_ARG(out && grafts && oid);
241
+ if ((*out = git_oidmap_get(grafts->commits, oid)) == NULL)
242
+ return GIT_ENOTFOUND;
243
+ return 0;
244
+ }
245
+
246
+ int git_grafts_oids(git_oid **out, size_t *out_len, git_grafts *grafts)
247
+ {
248
+ git_array_oid_t array = GIT_ARRAY_INIT;
249
+ const git_oid *oid;
250
+ size_t existing, i = 0;
251
+
252
+ GIT_ASSERT_ARG(out && grafts);
253
+
254
+ if ((existing = git_oidmap_size(grafts->commits)) > 0)
255
+ git_array_init_to_size(array, existing);
256
+
257
+ while (git_oidmap_iterate(NULL, grafts->commits, &i, &oid) == 0) {
258
+ git_oid *cpy = git_array_alloc(array);
259
+ GIT_ERROR_CHECK_ALLOC(cpy);
260
+ git_oid_cpy(cpy, oid);
261
+ }
262
+
263
+ *out = array.ptr;
264
+ *out_len = array.size;
265
+
266
+ return 0;
267
+ }
268
+
269
+ size_t git_grafts_size(git_grafts *grafts)
270
+ {
271
+ return git_oidmap_size(grafts->commits);
272
+ }
@@ -0,0 +1,36 @@
1
+ /*
2
+ * Copyright (C) the libgit2 contributors. All rights reserved.
3
+ *
4
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
5
+ * a Linking Exception. For full terms see the included COPYING file.
6
+ */
7
+ #ifndef INCLUDE_graft_h__
8
+ #define INCLUDE_graft_h__
9
+
10
+ #include "common.h"
11
+ #include "oidarray.h"
12
+ #include "oidmap.h"
13
+
14
+ /** graft commit */
15
+ typedef struct {
16
+ git_oid oid;
17
+ git_array_oid_t parents;
18
+ } git_commit_graft;
19
+
20
+ typedef struct git_grafts git_grafts;
21
+
22
+ int git_grafts_new(git_grafts **out, git_oid_t oid_type);
23
+ int git_grafts_open(git_grafts **out, const char *path, git_oid_t oid_type);
24
+ int git_grafts_open_or_refresh(git_grafts **out, const char *path, git_oid_t oid_type);
25
+ void git_grafts_free(git_grafts *grafts);
26
+ void git_grafts_clear(git_grafts *grafts);
27
+
28
+ int git_grafts_refresh(git_grafts *grafts);
29
+ int git_grafts_parse(git_grafts *grafts, const char *buf, size_t len);
30
+ int git_grafts_add(git_grafts *grafts, const git_oid *oid, git_array_oid_t parents);
31
+ int git_grafts_remove(git_grafts *grafts, const git_oid *oid);
32
+ int git_grafts_get(git_commit_graft **out, git_grafts *grafts, const git_oid *oid);
33
+ int git_grafts_oids(git_oid **out, size_t *out_len, git_grafts *grafts);
34
+ size_t git_grafts_size(git_grafts *grafts);
35
+
36
+ #endif