rugged 1.6.3 → 1.7.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (182) hide show
  1. checksums.yaml +4 -4
  2. data/ext/rugged/rugged_allocator.c +0 -54
  3. data/lib/rugged/version.rb +1 -1
  4. data/vendor/libgit2/CMakeLists.txt +3 -8
  5. data/vendor/libgit2/cmake/CheckPrototypeDefinitionSafe.cmake +16 -0
  6. data/vendor/libgit2/cmake/SelectGSSAPI.cmake +3 -3
  7. data/vendor/libgit2/cmake/SelectHTTPSBackend.cmake +21 -2
  8. data/vendor/libgit2/cmake/SelectHashes.cmake +4 -0
  9. data/vendor/libgit2/cmake/SelectXdiff.cmake +9 -0
  10. data/vendor/libgit2/deps/pcre/LICENCE +5 -5
  11. data/vendor/libgit2/deps/pcre/pcre.h +2 -2
  12. data/vendor/libgit2/deps/pcre/pcre_compile.c +6 -3
  13. data/vendor/libgit2/deps/pcre/pcre_exec.c +2 -2
  14. data/vendor/libgit2/deps/xdiff/CMakeLists.txt +28 -0
  15. data/vendor/libgit2/{src/libgit2 → deps}/xdiff/git-xdiff.h +4 -1
  16. data/vendor/libgit2/{src/libgit2 → deps}/xdiff/xdiffi.c +19 -18
  17. data/vendor/libgit2/{src/libgit2 → deps}/xdiff/xdiffi.h +2 -4
  18. data/vendor/libgit2/{src/libgit2 → deps}/xdiff/xemit.c +3 -3
  19. data/vendor/libgit2/{src/libgit2 → deps}/xdiff/xhistogram.c +7 -18
  20. data/vendor/libgit2/{src/libgit2 → deps}/xdiff/xmacros.h +18 -1
  21. data/vendor/libgit2/{src/libgit2 → deps}/xdiff/xmerge.c +24 -22
  22. data/vendor/libgit2/{src/libgit2 → deps}/xdiff/xpatience.c +21 -30
  23. data/vendor/libgit2/{src/libgit2 → deps}/xdiff/xprepare.c +13 -30
  24. data/vendor/libgit2/{src/libgit2 → deps}/xdiff/xutils.c +18 -1
  25. data/vendor/libgit2/{src/libgit2 → deps}/xdiff/xutils.h +2 -1
  26. data/vendor/libgit2/include/git2/common.h +26 -1
  27. data/vendor/libgit2/include/git2/diff.h +41 -3
  28. data/vendor/libgit2/include/git2/errors.h +4 -2
  29. data/vendor/libgit2/include/git2/index.h +9 -0
  30. data/vendor/libgit2/include/git2/oid.h +1 -1
  31. data/vendor/libgit2/include/git2/remote.h +18 -0
  32. data/vendor/libgit2/include/git2/repository.h +12 -2
  33. data/vendor/libgit2/include/git2/sys/alloc.h +0 -34
  34. data/vendor/libgit2/include/git2/sys/commit_graph.h +12 -2
  35. data/vendor/libgit2/include/git2/sys/midx.h +5 -1
  36. data/vendor/libgit2/include/git2/sys/stream.h +16 -2
  37. data/vendor/libgit2/include/git2/sys/transport.h +20 -2
  38. data/vendor/libgit2/include/git2/version.h +4 -4
  39. data/vendor/libgit2/include/git2/worktree.h +3 -1
  40. data/vendor/libgit2/src/CMakeLists.txt +34 -11
  41. data/vendor/libgit2/src/cli/cmd_clone.c +22 -6
  42. data/vendor/libgit2/src/cli/progress.c +9 -8
  43. data/vendor/libgit2/src/cli/progress.h +4 -4
  44. data/vendor/libgit2/src/libgit2/CMakeLists.txt +1 -19
  45. data/vendor/libgit2/src/libgit2/annotated_commit.c +2 -2
  46. data/vendor/libgit2/src/libgit2/annotated_commit.h +1 -1
  47. data/vendor/libgit2/src/libgit2/apply.c +4 -3
  48. data/vendor/libgit2/src/libgit2/blame.c +23 -16
  49. data/vendor/libgit2/src/libgit2/blame_git.c +0 -1
  50. data/vendor/libgit2/src/libgit2/branch.c +2 -2
  51. data/vendor/libgit2/src/libgit2/cherrypick.c +3 -3
  52. data/vendor/libgit2/src/libgit2/clone.c +3 -1
  53. data/vendor/libgit2/src/libgit2/commit.c +31 -9
  54. data/vendor/libgit2/src/libgit2/commit_graph.c +110 -43
  55. data/vendor/libgit2/src/libgit2/commit_graph.h +20 -4
  56. data/vendor/libgit2/src/libgit2/commit_list.c +12 -5
  57. data/vendor/libgit2/src/libgit2/commit_list.h +1 -0
  58. data/vendor/libgit2/src/libgit2/config.c +5 -2
  59. data/vendor/libgit2/src/libgit2/config_file.c +14 -8
  60. data/vendor/libgit2/src/libgit2/describe.c +10 -7
  61. data/vendor/libgit2/src/libgit2/diff.c +16 -7
  62. data/vendor/libgit2/src/libgit2/diff.h +6 -6
  63. data/vendor/libgit2/src/libgit2/diff_file.c +7 -7
  64. data/vendor/libgit2/src/libgit2/diff_generate.c +36 -15
  65. data/vendor/libgit2/src/libgit2/diff_parse.c +20 -4
  66. data/vendor/libgit2/src/libgit2/diff_print.c +26 -7
  67. data/vendor/libgit2/src/libgit2/diff_tform.c +4 -4
  68. data/vendor/libgit2/src/libgit2/diff_xdiff.h +1 -1
  69. data/vendor/libgit2/src/libgit2/email.c +4 -3
  70. data/vendor/libgit2/src/libgit2/errors.c +73 -18
  71. data/vendor/libgit2/src/libgit2/fetch.c +37 -9
  72. data/vendor/libgit2/src/libgit2/fetch.h +0 -2
  73. data/vendor/libgit2/src/libgit2/fetchhead.c +11 -9
  74. data/vendor/libgit2/src/libgit2/grafts.c +272 -0
  75. data/vendor/libgit2/src/libgit2/grafts.h +36 -0
  76. data/vendor/libgit2/src/libgit2/ident.c +3 -3
  77. data/vendor/libgit2/src/libgit2/index.c +323 -120
  78. data/vendor/libgit2/src/libgit2/index.h +14 -1
  79. data/vendor/libgit2/src/libgit2/indexer.c +10 -3
  80. data/vendor/libgit2/src/libgit2/iterator.c +20 -5
  81. data/vendor/libgit2/src/libgit2/iterator.h +3 -0
  82. data/vendor/libgit2/src/libgit2/libgit2.c +39 -0
  83. data/vendor/libgit2/src/libgit2/merge.c +14 -9
  84. data/vendor/libgit2/src/libgit2/merge_file.c +0 -2
  85. data/vendor/libgit2/src/libgit2/midx.c +66 -37
  86. data/vendor/libgit2/src/libgit2/midx.h +13 -3
  87. data/vendor/libgit2/src/libgit2/notes.c +9 -8
  88. data/vendor/libgit2/src/libgit2/object.c +40 -15
  89. data/vendor/libgit2/src/libgit2/object.h +6 -0
  90. data/vendor/libgit2/src/libgit2/odb.c +11 -5
  91. data/vendor/libgit2/src/libgit2/odb_pack.c +16 -3
  92. data/vendor/libgit2/src/libgit2/oid.c +7 -1
  93. data/vendor/libgit2/src/libgit2/oidarray.c +49 -3
  94. data/vendor/libgit2/src/libgit2/oidarray.h +5 -1
  95. data/vendor/libgit2/src/libgit2/pack-objects.c +19 -12
  96. data/vendor/libgit2/src/libgit2/pack-objects.h +5 -2
  97. data/vendor/libgit2/src/libgit2/pack.c +3 -3
  98. data/vendor/libgit2/src/libgit2/parse.c +7 -4
  99. data/vendor/libgit2/src/libgit2/parse.h +1 -1
  100. data/vendor/libgit2/src/libgit2/patch.h +7 -1
  101. data/vendor/libgit2/src/libgit2/patch_generate.c +24 -5
  102. data/vendor/libgit2/src/libgit2/patch_parse.c +16 -8
  103. data/vendor/libgit2/src/libgit2/push.c +2 -2
  104. data/vendor/libgit2/src/libgit2/reader.c +1 -1
  105. data/vendor/libgit2/src/libgit2/rebase.c +72 -84
  106. data/vendor/libgit2/src/libgit2/refdb_fs.c +22 -13
  107. data/vendor/libgit2/src/libgit2/refs.c +8 -1
  108. data/vendor/libgit2/src/libgit2/remote.c +15 -6
  109. data/vendor/libgit2/src/libgit2/remote.h +1 -0
  110. data/vendor/libgit2/src/libgit2/repository.c +580 -301
  111. data/vendor/libgit2/src/libgit2/repository.h +17 -2
  112. data/vendor/libgit2/src/libgit2/reset.c +2 -2
  113. data/vendor/libgit2/src/libgit2/revert.c +8 -11
  114. data/vendor/libgit2/src/libgit2/revwalk.c +26 -4
  115. data/vendor/libgit2/src/libgit2/stash.c +9 -8
  116. data/vendor/libgit2/src/libgit2/streams/mbedtls.c +0 -1
  117. data/vendor/libgit2/src/libgit2/streams/openssl.c +8 -16
  118. data/vendor/libgit2/src/libgit2/streams/schannel.c +715 -0
  119. data/vendor/libgit2/src/libgit2/streams/schannel.h +28 -0
  120. data/vendor/libgit2/src/libgit2/streams/socket.c +237 -51
  121. data/vendor/libgit2/src/libgit2/streams/socket.h +3 -1
  122. data/vendor/libgit2/src/libgit2/streams/stransport.c +40 -12
  123. data/vendor/libgit2/src/libgit2/streams/tls.c +5 -0
  124. data/vendor/libgit2/src/libgit2/submodule.h +3 -3
  125. data/vendor/libgit2/src/libgit2/threadstate.c +15 -2
  126. data/vendor/libgit2/src/libgit2/threadstate.h +1 -3
  127. data/vendor/libgit2/src/libgit2/transports/auth.h +1 -2
  128. data/vendor/libgit2/src/libgit2/transports/{auth_negotiate.c → auth_gssapi.c} +32 -32
  129. data/vendor/libgit2/src/libgit2/transports/auth_negotiate.h +1 -1
  130. data/vendor/libgit2/src/libgit2/transports/auth_ntlm.h +1 -1
  131. data/vendor/libgit2/src/libgit2/transports/{auth_ntlm.c → auth_ntlmclient.c} +12 -12
  132. data/vendor/libgit2/src/libgit2/transports/auth_sspi.c +341 -0
  133. data/vendor/libgit2/src/libgit2/transports/git.c +7 -8
  134. data/vendor/libgit2/src/libgit2/transports/http.c +7 -2
  135. data/vendor/libgit2/src/libgit2/transports/httpclient.c +5 -0
  136. data/vendor/libgit2/src/libgit2/transports/local.c +13 -4
  137. data/vendor/libgit2/src/libgit2/transports/smart.c +33 -27
  138. data/vendor/libgit2/src/libgit2/transports/smart.h +23 -8
  139. data/vendor/libgit2/src/libgit2/transports/smart_pkt.c +135 -15
  140. data/vendor/libgit2/src/libgit2/transports/smart_protocol.c +154 -47
  141. data/vendor/libgit2/src/libgit2/transports/ssh.c +3 -3
  142. data/vendor/libgit2/src/libgit2/transports/winhttp.c +14 -15
  143. data/vendor/libgit2/src/libgit2/tree-cache.c +26 -16
  144. data/vendor/libgit2/src/libgit2/tree-cache.h +5 -3
  145. data/vendor/libgit2/src/libgit2/tree.c +1 -1
  146. data/vendor/libgit2/src/libgit2/worktree.c +25 -10
  147. data/vendor/libgit2/src/util/alloc.c +65 -6
  148. data/vendor/libgit2/src/util/alloc.h +34 -9
  149. data/vendor/libgit2/src/util/allocators/failalloc.c +0 -60
  150. data/vendor/libgit2/src/util/allocators/failalloc.h +0 -6
  151. data/vendor/libgit2/src/util/allocators/stdalloc.c +2 -105
  152. data/vendor/libgit2/src/util/allocators/win32_leakcheck.c +0 -68
  153. data/vendor/libgit2/src/util/array.h +6 -1
  154. data/vendor/libgit2/src/util/cc-compat.h +2 -0
  155. data/vendor/libgit2/src/util/filebuf.c +6 -1
  156. data/vendor/libgit2/src/util/filebuf.h +19 -6
  157. data/vendor/libgit2/src/util/fs_path.c +1 -1
  158. data/vendor/libgit2/src/util/futils.c +8 -5
  159. data/vendor/libgit2/src/util/git2_features.h.in +9 -3
  160. data/vendor/libgit2/src/util/net.c +308 -157
  161. data/vendor/libgit2/src/util/net.h +25 -0
  162. data/vendor/libgit2/src/util/posix.c +54 -0
  163. data/vendor/libgit2/src/util/posix.h +22 -0
  164. data/vendor/libgit2/src/util/rand.c +6 -4
  165. data/vendor/libgit2/src/util/staticstr.h +66 -0
  166. data/vendor/libgit2/src/util/util.c +15 -10
  167. data/vendor/libgit2/src/util/util.h +24 -16
  168. data/vendor/libgit2/src/util/win32/error.c +1 -1
  169. data/vendor/libgit2/src/util/win32/path_w32.c +8 -8
  170. data/vendor/libgit2/src/util/win32/posix_w32.c +1 -1
  171. data/vendor/libgit2/src/util/win32/utf-conv.c +73 -75
  172. data/vendor/libgit2/src/util/win32/utf-conv.h +81 -14
  173. data/vendor/libgit2/src/util/win32/w32_util.c +1 -1
  174. metadata +29 -23
  175. data/vendor/libgit2/cmake/SelectWinHTTP.cmake +0 -17
  176. data/vendor/libgit2/src/libgit2/netops.c +0 -124
  177. data/vendor/libgit2/src/libgit2/netops.h +0 -68
  178. /data/vendor/libgit2/{src/libgit2 → deps}/xdiff/xdiff.h +0 -0
  179. /data/vendor/libgit2/{src/libgit2 → deps}/xdiff/xemit.h +0 -0
  180. /data/vendor/libgit2/{src/libgit2 → deps}/xdiff/xinclude.h +0 -0
  181. /data/vendor/libgit2/{src/libgit2 → deps}/xdiff/xprepare.h +0 -0
  182. /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
  }
@@ -17,9 +17,9 @@
17
17
  #include "remote.h"
18
18
  #include "refspec.h"
19
19
  #include "pack.h"
20
- #include "netops.h"
21
20
  #include "repository.h"
22
21
  #include "refs.h"
22
+ #include "transports/smart.h"
23
23
 
24
24
  static int maybe_want(git_remote *remote, git_remote_head *head, git_refspec *tagspec, git_remote_autotag_option_t tagopt)
25
25
  {
@@ -59,8 +59,10 @@ static int mark_local(git_remote *remote)
59
59
  return -1;
60
60
 
61
61
  git_vector_foreach(&remote->refs, i, head) {
62
- /* If we have the object, mark it so we don't ask for it */
63
- 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))
64
66
  head->local = 1;
65
67
  else
66
68
  remote->need_pack = 1;
@@ -76,7 +78,7 @@ static int maybe_want_oid(git_remote *remote, git_refspec *spec)
76
78
  oid_head = git__calloc(1, sizeof(git_remote_head));
77
79
  GIT_ERROR_CHECK_ALLOC(oid_head);
78
80
 
79
- git_oid__fromstr(&oid_head->oid, spec->src, GIT_OID_SHA1);
81
+ git_oid__fromstr(&oid_head->oid, spec->src, remote->repo->oid_type);
80
82
 
81
83
  if (spec->dst) {
82
84
  oid_head->name = git__strdup(spec->dst);
@@ -137,7 +139,7 @@ static int filter_wants(git_remote *remote, const git_fetch_options *opts)
137
139
 
138
140
  /* Handle explicitly specified OID specs */
139
141
  git_vector_foreach(&remote->active_refspecs, i, spec) {
140
- if (!git_oid__is_hexstr(spec->src, GIT_OID_SHA1))
142
+ if (!git_oid__is_hexstr(spec->src, remote->repo->oid_type))
141
143
  continue;
142
144
 
143
145
  if (!(remote_caps & oid_mask)) {
@@ -166,9 +168,15 @@ cleanup:
166
168
  int git_fetch_negotiate(git_remote *remote, const git_fetch_options *opts)
167
169
  {
168
170
  git_transport *t = remote->transport;
171
+ int error;
169
172
 
170
173
  remote->need_pack = 0;
171
174
 
175
+ if (opts) {
176
+ GIT_ASSERT_ARG(opts->depth >= 0);
177
+ remote->nego.depth = opts->depth;
178
+ }
179
+
172
180
  if (filter_wants(remote, opts) < 0)
173
181
  return -1;
174
182
 
@@ -180,20 +188,40 @@ int git_fetch_negotiate(git_remote *remote, const git_fetch_options *opts)
180
188
  * Now we have everything set up so we can start tell the
181
189
  * server what we want and what we have.
182
190
  */
183
- 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,
184
200
  remote->repo,
185
- (const git_remote_head * const *)remote->refs.contents,
186
- remote->refs.length);
201
+ &remote->nego);
202
+
203
+ git__free(remote->nego.shallow_roots);
204
+
205
+ return error;
187
206
  }
188
207
 
189
208
  int git_fetch_download_pack(git_remote *remote)
190
209
  {
210
+ git_oidarray shallow_roots = { NULL };
191
211
  git_transport *t = remote->transport;
212
+ int error;
192
213
 
193
214
  if (!remote->need_pack)
194
215
  return 0;
195
216
 
196
- 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;
197
225
  }
198
226
 
199
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_SHA1_HEXSIZE + 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_SHA1_HEXSIZE] = '\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_SHA1_HEXSIZE) {
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, GIT_OID_SHA1) < 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
@@ -42,7 +42,7 @@ static int ident_find_id(
42
42
  static int ident_insert_id(
43
43
  git_str *to, const git_str *from, const git_filter_source *src)
44
44
  {
45
- char oid[GIT_OID_SHA1_HEXSIZE+1];
45
+ char oid[GIT_OID_MAX_HEXSIZE + 1];
46
46
  const char *id_start, *id_end, *from_end = from->ptr + from->size;
47
47
  size_t need_size;
48
48
 
@@ -57,7 +57,7 @@ static int ident_insert_id(
57
57
  return GIT_PASSTHROUGH;
58
58
 
59
59
  need_size = (size_t)(id_start - from->ptr) +
60
- 5 /* "$Id: " */ + GIT_OID_SHA1_HEXSIZE + 2 /* " $" */ +
60
+ 5 /* "$Id: " */ + GIT_OID_MAX_HEXSIZE + 2 /* " $" */ +
61
61
  (size_t)(from_end - id_end);
62
62
 
63
63
  if (git_str_grow(to, need_size) < 0)
@@ -65,7 +65,7 @@ static int ident_insert_id(
65
65
 
66
66
  git_str_set(to, from->ptr, (size_t)(id_start - from->ptr));
67
67
  git_str_put(to, "$Id: ", 5);
68
- git_str_put(to, oid, GIT_OID_SHA1_HEXSIZE);
68
+ git_str_puts(to, oid);
69
69
  git_str_put(to, " $", 2);
70
70
  git_str_put(to, id_end, (size_t)(from_end - id_end));
71
71