rugged 1.6.5 → 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_file.c +14 -8
  59. data/vendor/libgit2/src/libgit2/describe.c +10 -7
  60. data/vendor/libgit2/src/libgit2/diff.c +16 -7
  61. data/vendor/libgit2/src/libgit2/diff.h +6 -6
  62. data/vendor/libgit2/src/libgit2/diff_file.c +7 -7
  63. data/vendor/libgit2/src/libgit2/diff_generate.c +36 -15
  64. data/vendor/libgit2/src/libgit2/diff_parse.c +20 -4
  65. data/vendor/libgit2/src/libgit2/diff_print.c +26 -7
  66. data/vendor/libgit2/src/libgit2/diff_tform.c +4 -4
  67. data/vendor/libgit2/src/libgit2/diff_xdiff.h +1 -1
  68. data/vendor/libgit2/src/libgit2/email.c +4 -3
  69. data/vendor/libgit2/src/libgit2/errors.c +73 -18
  70. data/vendor/libgit2/src/libgit2/fetch.c +37 -9
  71. data/vendor/libgit2/src/libgit2/fetch.h +0 -2
  72. data/vendor/libgit2/src/libgit2/fetchhead.c +11 -9
  73. data/vendor/libgit2/src/libgit2/grafts.c +272 -0
  74. data/vendor/libgit2/src/libgit2/grafts.h +36 -0
  75. data/vendor/libgit2/src/libgit2/ident.c +3 -3
  76. data/vendor/libgit2/src/libgit2/index.c +325 -125
  77. data/vendor/libgit2/src/libgit2/index.h +14 -1
  78. data/vendor/libgit2/src/libgit2/indexer.c +10 -3
  79. data/vendor/libgit2/src/libgit2/iterator.c +20 -5
  80. data/vendor/libgit2/src/libgit2/iterator.h +3 -0
  81. data/vendor/libgit2/src/libgit2/libgit2.c +39 -0
  82. data/vendor/libgit2/src/libgit2/merge.c +14 -9
  83. data/vendor/libgit2/src/libgit2/merge_file.c +0 -2
  84. data/vendor/libgit2/src/libgit2/midx.c +66 -37
  85. data/vendor/libgit2/src/libgit2/midx.h +13 -3
  86. data/vendor/libgit2/src/libgit2/notes.c +9 -8
  87. data/vendor/libgit2/src/libgit2/object.c +40 -15
  88. data/vendor/libgit2/src/libgit2/object.h +6 -0
  89. data/vendor/libgit2/src/libgit2/odb.c +11 -5
  90. data/vendor/libgit2/src/libgit2/odb_pack.c +16 -3
  91. data/vendor/libgit2/src/libgit2/oid.c +7 -1
  92. data/vendor/libgit2/src/libgit2/oidarray.c +49 -3
  93. data/vendor/libgit2/src/libgit2/oidarray.h +5 -1
  94. data/vendor/libgit2/src/libgit2/pack-objects.c +19 -12
  95. data/vendor/libgit2/src/libgit2/pack-objects.h +5 -2
  96. data/vendor/libgit2/src/libgit2/pack.c +3 -3
  97. data/vendor/libgit2/src/libgit2/parse.c +7 -4
  98. data/vendor/libgit2/src/libgit2/parse.h +1 -1
  99. data/vendor/libgit2/src/libgit2/patch.h +7 -1
  100. data/vendor/libgit2/src/libgit2/patch_generate.c +24 -5
  101. data/vendor/libgit2/src/libgit2/patch_parse.c +16 -8
  102. data/vendor/libgit2/src/libgit2/push.c +2 -2
  103. data/vendor/libgit2/src/libgit2/reader.c +1 -1
  104. data/vendor/libgit2/src/libgit2/rebase.c +72 -84
  105. data/vendor/libgit2/src/libgit2/refdb_fs.c +22 -13
  106. data/vendor/libgit2/src/libgit2/refs.c +8 -1
  107. data/vendor/libgit2/src/libgit2/remote.c +15 -6
  108. data/vendor/libgit2/src/libgit2/remote.h +1 -0
  109. data/vendor/libgit2/src/libgit2/repository.c +580 -301
  110. data/vendor/libgit2/src/libgit2/repository.h +17 -2
  111. data/vendor/libgit2/src/libgit2/reset.c +2 -2
  112. data/vendor/libgit2/src/libgit2/revert.c +8 -11
  113. data/vendor/libgit2/src/libgit2/revparse.c +1 -4
  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 +136 -17
  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
@@ -27,7 +27,6 @@ bool git_smart__ofs_delta_enabled = true;
27
27
 
28
28
  int git_smart__store_refs(transport_smart *t, int flushes)
29
29
  {
30
- gitno_buffer *buf = &t->buffer;
31
30
  git_vector *refs = &t->refs;
32
31
  int error, flush = 0, recvd;
33
32
  const char *line_end = NULL;
@@ -45,8 +44,10 @@ int git_smart__store_refs(transport_smart *t, int flushes)
45
44
  pkt = NULL;
46
45
 
47
46
  do {
48
- if (buf->offset > 0)
49
- error = git_pkt_parse_line(&pkt, &line_end, buf->data, buf->offset, &pkt_parse_data);
47
+ if (t->buffer.len > 0)
48
+ error = git_pkt_parse_line(&pkt, &line_end,
49
+ t->buffer.data, t->buffer.len,
50
+ &pkt_parse_data);
50
51
  else
51
52
  error = GIT_EBUFS;
52
53
 
@@ -54,7 +55,7 @@ int git_smart__store_refs(transport_smart *t, int flushes)
54
55
  return error;
55
56
 
56
57
  if (error == GIT_EBUFS) {
57
- if ((recvd = gitno_recv(buf)) < 0)
58
+ if ((recvd = git_smart__recv(t)) < 0)
58
59
  return recvd;
59
60
 
60
61
  if (recvd == 0) {
@@ -65,8 +66,7 @@ int git_smart__store_refs(transport_smart *t, int flushes)
65
66
  continue;
66
67
  }
67
68
 
68
- if (gitno_consume(buf, line_end) < 0)
69
- return -1;
69
+ git_staticstr_consume(&t->buffer, line_end);
70
70
 
71
71
  if (pkt->type == GIT_PKT_ERR) {
72
72
  git_error_set(GIT_ERROR_NET, "remote error: %s", ((git_pkt_err *)pkt)->error);
@@ -243,6 +243,12 @@ int git_smart__detect_caps(
243
243
  continue;
244
244
  }
245
245
 
246
+ if (!git__prefixcmp(ptr, GIT_CAP_SHALLOW)) {
247
+ caps->common = caps->shallow = 1;
248
+ ptr += strlen(GIT_CAP_SHALLOW);
249
+ continue;
250
+ }
251
+
246
252
  /* We don't know this capability, so skip it */
247
253
  ptr = strchr(ptr, ' ');
248
254
  }
@@ -250,16 +256,23 @@ int git_smart__detect_caps(
250
256
  return 0;
251
257
  }
252
258
 
253
- static int recv_pkt(git_pkt **out_pkt, git_pkt_type *out_type, gitno_buffer *buf)
259
+ static int recv_pkt(
260
+ git_pkt **out_pkt,
261
+ git_pkt_type *out_type,
262
+ transport_smart *t)
254
263
  {
255
- const char *ptr = buf->data, *line_end = ptr;
264
+ const char *ptr = t->buffer.data, *line_end = ptr;
256
265
  git_pkt *pkt = NULL;
257
266
  git_pkt_parse_data pkt_parse_data = { 0 };
258
267
  int error = 0, ret;
259
268
 
269
+ pkt_parse_data.oid_type = t->owner->repo->oid_type;
270
+ pkt_parse_data.seen_capabilities = 1;
271
+
260
272
  do {
261
- if (buf->offset > 0)
262
- error = git_pkt_parse_line(&pkt, &line_end, ptr, buf->offset, &pkt_parse_data);
273
+ if (t->buffer.len > 0)
274
+ error = git_pkt_parse_line(&pkt, &line_end, ptr,
275
+ t->buffer.len, &pkt_parse_data);
263
276
  else
264
277
  error = GIT_EBUFS;
265
278
 
@@ -269,7 +282,7 @@ static int recv_pkt(git_pkt **out_pkt, git_pkt_type *out_type, gitno_buffer *buf
269
282
  if (error < 0 && error != GIT_EBUFS)
270
283
  return error;
271
284
 
272
- if ((ret = gitno_recv(buf)) < 0) {
285
+ if ((ret = git_smart__recv(t)) < 0) {
273
286
  return ret;
274
287
  } else if (ret == 0) {
275
288
  git_error_set(GIT_ERROR_NET, "early EOF");
@@ -277,8 +290,7 @@ static int recv_pkt(git_pkt **out_pkt, git_pkt_type *out_type, gitno_buffer *buf
277
290
  }
278
291
  } while (error);
279
292
 
280
- if (gitno_consume(buf, line_end) < 0)
281
- return -1;
293
+ git_staticstr_consume(&t->buffer, line_end);
282
294
 
283
295
  if (out_type != NULL)
284
296
  *out_type = pkt->type;
@@ -293,11 +305,10 @@ static int recv_pkt(git_pkt **out_pkt, git_pkt_type *out_type, gitno_buffer *buf
293
305
  static int store_common(transport_smart *t)
294
306
  {
295
307
  git_pkt *pkt = NULL;
296
- gitno_buffer *buf = &t->buffer;
297
308
  int error;
298
309
 
299
310
  do {
300
- if ((error = recv_pkt(&pkt, NULL, buf)) < 0)
311
+ if ((error = recv_pkt(&pkt, NULL, t)) < 0)
301
312
  return error;
302
313
 
303
314
  if (pkt->type != GIT_PKT_ACK) {
@@ -314,7 +325,7 @@ static int store_common(transport_smart *t)
314
325
  return 0;
315
326
  }
316
327
 
317
- static int wait_while_ack(gitno_buffer *buf)
328
+ static int wait_while_ack(transport_smart *t)
318
329
  {
319
330
  int error;
320
331
  git_pkt *pkt = NULL;
@@ -323,7 +334,7 @@ static int wait_while_ack(gitno_buffer *buf)
323
334
  while (1) {
324
335
  git_pkt_free(pkt);
325
336
 
326
- if ((error = recv_pkt(&pkt, NULL, buf)) < 0)
337
+ if ((error = recv_pkt(&pkt, NULL, t)) < 0)
327
338
  return error;
328
339
 
329
340
  if (pkt->type == GIT_PKT_NAK)
@@ -344,11 +355,51 @@ static int wait_while_ack(gitno_buffer *buf)
344
355
  return 0;
345
356
  }
346
357
 
347
- int git_smart__negotiate_fetch(git_transport *transport, git_repository *repo, const git_remote_head * const *wants, size_t count)
358
+ static int cap_not_sup_err(const char *cap_name)
359
+ {
360
+ git_error_set(GIT_ERROR_NET, "server doesn't support %s", cap_name);
361
+ return GIT_EINVALID;
362
+ }
363
+
364
+ /* Disables server capabilities we're not interested in */
365
+ static int setup_caps(
366
+ transport_smart_caps *caps,
367
+ const git_fetch_negotiation *wants)
368
+ {
369
+ if (wants->depth > 0) {
370
+ if (!caps->shallow)
371
+ return cap_not_sup_err(GIT_CAP_SHALLOW);
372
+ } else {
373
+ caps->shallow = 0;
374
+ }
375
+
376
+ return 0;
377
+ }
378
+
379
+ static int setup_shallow_roots(
380
+ git_array_oid_t *out,
381
+ const git_fetch_negotiation *wants)
382
+ {
383
+ git_array_clear(*out);
384
+
385
+ if (wants->shallow_roots_len > 0) {
386
+ git_array_init_to_size(*out, wants->shallow_roots_len);
387
+ GIT_ERROR_CHECK_ALLOC(out->ptr);
388
+
389
+ memcpy(out->ptr, wants->shallow_roots,
390
+ sizeof(git_oid) * wants->shallow_roots_len);
391
+ }
392
+
393
+ return 0;
394
+ }
395
+
396
+ int git_smart__negotiate_fetch(
397
+ git_transport *transport,
398
+ git_repository *repo,
399
+ const git_fetch_negotiation *wants)
348
400
  {
349
401
  transport_smart *t = (transport_smart *)transport;
350
402
  git_revwalk__push_options opts = GIT_REVWALK__PUSH_OPTIONS_INIT;
351
- gitno_buffer *buf = &t->buffer;
352
403
  git_str data = GIT_STR_INIT;
353
404
  git_revwalk *walk = NULL;
354
405
  int error = -1;
@@ -356,7 +407,11 @@ int git_smart__negotiate_fetch(git_transport *transport, git_repository *repo, c
356
407
  unsigned int i;
357
408
  git_oid oid;
358
409
 
359
- if ((error = git_pkt_buffer_wants(wants, count, &t->caps, &data)) < 0)
410
+ if ((error = setup_caps(&t->caps, wants)) < 0 ||
411
+ (error = setup_shallow_roots(&t->shallow_roots, wants)) < 0)
412
+ return error;
413
+
414
+ if ((error = git_pkt_buffer_wants(wants, &t->caps, &data)) < 0)
360
415
  return error;
361
416
 
362
417
  if ((error = git_revwalk_new(&walk, repo)) < 0)
@@ -366,6 +421,37 @@ int git_smart__negotiate_fetch(git_transport *transport, git_repository *repo, c
366
421
  if ((error = git_revwalk__push_glob(walk, "refs/*", &opts)) < 0)
367
422
  goto on_error;
368
423
 
424
+ if (wants->depth > 0) {
425
+ git_pkt_shallow *pkt;
426
+
427
+ if ((error = git_smart__negotiation_step(&t->parent, data.ptr, data.size)) < 0)
428
+ goto on_error;
429
+
430
+ while ((error = recv_pkt((git_pkt **)&pkt, NULL, t)) == 0) {
431
+ bool complete = false;
432
+
433
+ if (pkt->type == GIT_PKT_SHALLOW) {
434
+ error = git_oidarray__add(&t->shallow_roots, &pkt->oid);
435
+ } else if (pkt->type == GIT_PKT_UNSHALLOW) {
436
+ git_oidarray__remove(&t->shallow_roots, &pkt->oid);
437
+ } else if (pkt->type == GIT_PKT_FLUSH) {
438
+ /* Server is done, stop processing shallow oids */
439
+ complete = true;
440
+ } else {
441
+ git_error_set(GIT_ERROR_NET, "unexpected packet type");
442
+ error = -1;
443
+ }
444
+
445
+ git_pkt_free((git_pkt *) pkt);
446
+
447
+ if (complete || error < 0)
448
+ break;
449
+ }
450
+
451
+ if (error < 0)
452
+ goto on_error;
453
+ }
454
+
369
455
  /*
370
456
  * Our support for ACK extensions is simply to parse them. On
371
457
  * the first ACK we will accept that as enough common
@@ -406,7 +492,7 @@ int git_smart__negotiate_fetch(git_transport *transport, git_repository *repo, c
406
492
  if ((error = store_common(t)) < 0)
407
493
  goto on_error;
408
494
  } else {
409
- if ((error = recv_pkt(NULL, &pkt_type, buf)) < 0)
495
+ if ((error = recv_pkt(NULL, &pkt_type, t)) < 0)
410
496
  goto on_error;
411
497
 
412
498
  if (pkt_type == GIT_PKT_ACK) {
@@ -428,7 +514,7 @@ int git_smart__negotiate_fetch(git_transport *transport, git_repository *repo, c
428
514
  git_pkt_ack *pkt;
429
515
  unsigned int j;
430
516
 
431
- if ((error = git_pkt_buffer_wants(wants, count, &t->caps, &data)) < 0)
517
+ if ((error = git_pkt_buffer_wants(wants, &t->caps, &data)) < 0)
432
518
  goto on_error;
433
519
 
434
520
  git_vector_foreach(&t->common, j, pkt) {
@@ -448,7 +534,7 @@ int git_smart__negotiate_fetch(git_transport *transport, git_repository *repo, c
448
534
  git_pkt_ack *pkt;
449
535
  unsigned int j;
450
536
 
451
- if ((error = git_pkt_buffer_wants(wants, count, &t->caps, &data)) < 0)
537
+ if ((error = git_pkt_buffer_wants(wants, &t->caps, &data)) < 0)
452
538
  goto on_error;
453
539
 
454
540
  git_vector_foreach(&t->common, j, pkt) {
@@ -466,10 +552,11 @@ int git_smart__negotiate_fetch(git_transport *transport, git_repository *repo, c
466
552
  goto on_error;
467
553
 
468
554
  if (t->cancelled.val) {
469
- git_error_set(GIT_ERROR_NET, "The fetch was cancelled by the user");
555
+ git_error_set(GIT_ERROR_NET, "the fetch was cancelled");
470
556
  error = GIT_EUSER;
471
557
  goto on_error;
472
558
  }
559
+
473
560
  if ((error = git_smart__negotiation_step(&t->parent, data.ptr, data.size)) < 0)
474
561
  goto on_error;
475
562
 
@@ -478,7 +565,7 @@ int git_smart__negotiate_fetch(git_transport *transport, git_repository *repo, c
478
565
 
479
566
  /* Now let's eat up whatever the server gives us */
480
567
  if (!t->caps.multi_ack && !t->caps.multi_ack_detailed) {
481
- if ((error = recv_pkt(NULL, &pkt_type, buf)) < 0)
568
+ if ((error = recv_pkt(NULL, &pkt_type, t)) < 0)
482
569
  return error;
483
570
 
484
571
  if (pkt_type != GIT_PKT_ACK && pkt_type != GIT_PKT_NAK) {
@@ -486,7 +573,7 @@ int git_smart__negotiate_fetch(git_transport *transport, git_repository *repo, c
486
573
  return -1;
487
574
  }
488
575
  } else {
489
- error = wait_while_ack(buf);
576
+ error = wait_while_ack(t);
490
577
  }
491
578
 
492
579
  return error;
@@ -497,7 +584,29 @@ on_error:
497
584
  return error;
498
585
  }
499
586
 
500
- static int no_sideband(transport_smart *t, struct git_odb_writepack *writepack, gitno_buffer *buf, git_indexer_progress *stats)
587
+ int git_smart__shallow_roots(git_oidarray *out, git_transport *transport)
588
+ {
589
+ transport_smart *t = (transport_smart *)transport;
590
+ size_t len;
591
+
592
+ GIT_ERROR_CHECK_ALLOC_MULTIPLY(&len, t->shallow_roots.size, sizeof(git_oid));
593
+
594
+ out->count = t->shallow_roots.size;
595
+
596
+ if (len) {
597
+ out->ids = git__malloc(len);
598
+ memcpy(out->ids, t->shallow_roots.ptr, len);
599
+ } else {
600
+ out->ids = NULL;
601
+ }
602
+
603
+ return 0;
604
+ }
605
+
606
+ static int no_sideband(
607
+ transport_smart *t,
608
+ struct git_odb_writepack *writepack,
609
+ git_indexer_progress *stats)
501
610
  {
502
611
  int recvd;
503
612
 
@@ -507,12 +616,12 @@ static int no_sideband(transport_smart *t, struct git_odb_writepack *writepack,
507
616
  return GIT_EUSER;
508
617
  }
509
618
 
510
- if (writepack->append(writepack, buf->data, buf->offset, stats) < 0)
619
+ if (writepack->append(writepack, t->buffer.data, t->buffer.len, stats) < 0)
511
620
  return -1;
512
621
 
513
- gitno_consume_n(buf, buf->offset);
622
+ git_staticstr_clear(&t->buffer);
514
623
 
515
- if ((recvd = gitno_recv(buf)) < 0)
624
+ if ((recvd = git_smart__recv(t)) < 0)
516
625
  return recvd;
517
626
  } while(recvd > 0);
518
627
 
@@ -554,7 +663,6 @@ int git_smart__download_pack(
554
663
  git_indexer_progress *stats)
555
664
  {
556
665
  transport_smart *t = (transport_smart *)transport;
557
- gitno_buffer *buf = &t->buffer;
558
666
  git_odb *odb;
559
667
  struct git_odb_writepack *writepack = NULL;
560
668
  int error = 0;
@@ -573,9 +681,10 @@ int git_smart__download_pack(
573
681
  t->packetsize_payload = &npp;
574
682
 
575
683
  /* We might have something in the buffer already from negotiate_fetch */
576
- if (t->buffer.offset > 0 && !t->cancelled.val)
577
- if (t->packetsize_cb(t->buffer.offset, t->packetsize_payload))
684
+ if (t->buffer.len > 0 && !t->cancelled.val) {
685
+ if (t->packetsize_cb(t->buffer.len, t->packetsize_payload))
578
686
  git_atomic32_set(&t->cancelled, 1);
687
+ }
579
688
  }
580
689
 
581
690
  if ((error = git_repository_odb__weakptr(&odb, repo)) < 0 ||
@@ -588,7 +697,7 @@ int git_smart__download_pack(
588
697
  * check which one belongs there.
589
698
  */
590
699
  if (!t->caps.side_band && !t->caps.side_band_64k) {
591
- error = no_sideband(t, writepack, buf, stats);
700
+ error = no_sideband(t, writepack, stats);
592
701
  goto done;
593
702
  }
594
703
 
@@ -602,7 +711,7 @@ int git_smart__download_pack(
602
711
  goto done;
603
712
  }
604
713
 
605
- if ((error = recv_pkt(&pkt, NULL, buf)) >= 0) {
714
+ if ((error = recv_pkt(&pkt, NULL, t)) >= 0) {
606
715
  /* Check cancellation after network call */
607
716
  if (t->cancelled.val) {
608
717
  git_error_clear();
@@ -807,15 +916,15 @@ static int parse_report(transport_smart *transport, git_push *push)
807
916
  git_pkt *pkt = NULL;
808
917
  git_pkt_parse_data pkt_parse_data = { 0 };
809
918
  const char *line_end = NULL;
810
- gitno_buffer *buf = &transport->buffer;
811
919
  int error, recvd;
812
920
  git_str data_pkt_buf = GIT_STR_INIT;
813
921
 
814
922
  for (;;) {
815
- if (buf->offset > 0)
923
+ if (transport->buffer.len > 0)
816
924
  error = git_pkt_parse_line(&pkt, &line_end,
817
- buf->data, buf->offset,
818
- &pkt_parse_data);
925
+ transport->buffer.data,
926
+ transport->buffer.len,
927
+ &pkt_parse_data);
819
928
  else
820
929
  error = GIT_EBUFS;
821
930
 
@@ -825,7 +934,7 @@ static int parse_report(transport_smart *transport, git_push *push)
825
934
  }
826
935
 
827
936
  if (error == GIT_EBUFS) {
828
- if ((recvd = gitno_recv(buf)) < 0) {
937
+ if ((recvd = git_smart__recv(transport)) < 0) {
829
938
  error = recvd;
830
939
  goto done;
831
940
  }
@@ -838,9 +947,7 @@ static int parse_report(transport_smart *transport, git_push *push)
838
947
  continue;
839
948
  }
840
949
 
841
- if (gitno_consume(buf, line_end) < 0)
842
- return -1;
843
-
950
+ git_staticstr_consume(&transport->buffer, line_end);
844
951
  error = 0;
845
952
 
846
953
  switch (pkt->type) {
@@ -1005,7 +1112,7 @@ struct push_packbuilder_payload
1005
1112
  git_push_transfer_progress_cb cb;
1006
1113
  void *cb_payload;
1007
1114
  size_t last_bytes;
1008
- double last_progress_report_time;
1115
+ uint64_t last_progress_report_time;
1009
1116
  };
1010
1117
 
1011
1118
  static int stream_thunk(void *buf, size_t size, void *data)
@@ -1017,11 +1124,11 @@ static int stream_thunk(void *buf, size_t size, void *data)
1017
1124
  return error;
1018
1125
 
1019
1126
  if (payload->cb) {
1020
- double current_time = git__timer();
1021
- double elapsed = current_time - payload->last_progress_report_time;
1127
+ uint64_t current_time = git_time_monotonic();
1128
+ uint64_t elapsed = current_time - payload->last_progress_report_time;
1022
1129
  payload->last_bytes += size;
1023
1130
 
1024
- if (elapsed < 0 || elapsed >= MIN_PROGRESS_UPDATE_INTERVAL) {
1131
+ if (elapsed >= MIN_PROGRESS_UPDATE_INTERVAL) {
1025
1132
  payload->last_progress_report_time = current_time;
1026
1133
  error = payload->cb(payload->pb->nr_written, payload->pb->nr_objects, payload->last_bytes, payload->cb_payload);
1027
1134
  }
@@ -13,7 +13,6 @@
13
13
 
14
14
  #include "runtime.h"
15
15
  #include "net.h"
16
- #include "netops.h"
17
16
  #include "smart.h"
18
17
  #include "streams/socket.h"
19
18
  #include "sysdir.h"
@@ -878,11 +877,12 @@ static int _git_ssh_setup_conn(
878
877
  t->current_stream = s;
879
878
 
880
879
  done:
880
+ if (known_hosts)
881
+ libssh2_knownhost_free(known_hosts);
882
+
881
883
  if (error < 0) {
882
884
  ssh_stream_free(*stream);
883
885
 
884
- if (known_hosts)
885
- libssh2_knownhost_free(known_hosts);
886
886
  if (session)
887
887
  libssh2_session_free(session);
888
888
  }
@@ -13,7 +13,6 @@
13
13
  #include "git2/transport.h"
14
14
  #include "posix.h"
15
15
  #include "str.h"
16
- #include "netops.h"
17
16
  #include "smart.h"
18
17
  #include "remote.h"
19
18
  #include "repository.h"
@@ -158,10 +157,10 @@ static int apply_userpass_credentials(HINTERNET request, DWORD target, int mecha
158
157
  goto done;
159
158
  }
160
159
 
161
- if ((error = user_len = git__utf8_to_16_alloc(&user, c->username)) < 0)
160
+ if ((error = user_len = git_utf8_to_16_alloc(&user, c->username)) < 0)
162
161
  goto done;
163
162
 
164
- if ((error = pass_len = git__utf8_to_16_alloc(&pass, c->password)) < 0)
163
+ if ((error = pass_len = git_utf8_to_16_alloc(&pass, c->password)) < 0)
165
164
  goto done;
166
165
 
167
166
  if (!WinHttpSetCredentials(request, target, native_scheme, user, pass, NULL)) {
@@ -242,7 +241,7 @@ static int acquire_fallback_cred(
242
241
  HRESULT hCoInitResult;
243
242
 
244
243
  /* Convert URL to wide characters */
245
- if (git__utf8_to_16_alloc(&wide_url, url) < 0) {
244
+ if (git_utf8_to_16_alloc(&wide_url, url) < 0) {
246
245
  git_error_set(GIT_ERROR_OS, "failed to convert string to wide form");
247
246
  return -1;
248
247
  }
@@ -397,7 +396,7 @@ static int winhttp_stream_connect(winhttp_stream *s)
397
396
  return -1;
398
397
 
399
398
  /* Convert URL to wide characters */
400
- if (git__utf8_to_16_alloc(&s->request_uri, git_str_cstr(&buf)) < 0) {
399
+ if (git_utf8_to_16_alloc(&s->request_uri, git_str_cstr(&buf)) < 0) {
401
400
  git_error_set(GIT_ERROR_OS, "failed to convert string to wide form");
402
401
  goto on_error;
403
402
  }
@@ -444,10 +443,10 @@ static int winhttp_stream_connect(winhttp_stream *s)
444
443
 
445
444
  git_net_url_dispose(&t->proxy.url);
446
445
 
447
- if ((error = git_net_url_parse(&t->proxy.url, proxy_url)) < 0)
446
+ if ((error = git_net_url_parse_http(&t->proxy.url, proxy_url)) < 0)
448
447
  goto on_error;
449
448
 
450
- if (strcmp(t->proxy.url.scheme, "http") != 0 && strcmp(t->proxy.url.scheme, "https") != 0) {
449
+ if (!git_net_url_valid(&t->proxy.url)) {
451
450
  git_error_set(GIT_ERROR_HTTP, "invalid URL: '%s'", proxy_url);
452
451
  error = -1;
453
452
  goto on_error;
@@ -473,7 +472,7 @@ static int winhttp_stream_connect(winhttp_stream *s)
473
472
  }
474
473
 
475
474
  /* Convert URL to wide characters */
476
- error = git__utf8_to_16_alloc(&proxy_wide, processed_url.ptr);
475
+ error = git_utf8_to_16_alloc(&proxy_wide, processed_url.ptr);
477
476
  git_str_dispose(&processed_url);
478
477
  if (error < 0)
479
478
  goto on_error;
@@ -531,7 +530,7 @@ static int winhttp_stream_connect(winhttp_stream *s)
531
530
  s->service) < 0)
532
531
  goto on_error;
533
532
 
534
- if (git__utf8_to_16(ct, MAX_CONTENT_TYPE_LEN, git_str_cstr(&buf)) < 0) {
533
+ if (git_utf8_to_16(ct, MAX_CONTENT_TYPE_LEN, git_str_cstr(&buf)) < 0) {
535
534
  git_error_set(GIT_ERROR_OS, "failed to convert content-type to wide characters");
536
535
  goto on_error;
537
536
  }
@@ -548,7 +547,7 @@ static int winhttp_stream_connect(winhttp_stream *s)
548
547
  s->service) < 0)
549
548
  goto on_error;
550
549
 
551
- if (git__utf8_to_16(ct, MAX_CONTENT_TYPE_LEN, git_str_cstr(&buf)) < 0) {
550
+ if (git_utf8_to_16(ct, MAX_CONTENT_TYPE_LEN, git_str_cstr(&buf)) < 0) {
552
551
  git_error_set(GIT_ERROR_OS, "failed to convert accept header to wide characters");
553
552
  goto on_error;
554
553
  }
@@ -568,7 +567,7 @@ static int winhttp_stream_connect(winhttp_stream *s)
568
567
  git_str_puts(&buf, t->owner->connect_opts.custom_headers.strings[i]);
569
568
 
570
569
  /* Convert header to wide characters */
571
- if ((error = git__utf8_to_16_alloc(&custom_header_wide, git_str_cstr(&buf))) < 0)
570
+ if ((error = git_utf8_to_16_alloc(&custom_header_wide, git_str_cstr(&buf))) < 0)
572
571
  goto on_error;
573
572
 
574
573
  if (!WinHttpAddRequestHeaders(s->request, custom_header_wide, (ULONG)-1L,
@@ -783,7 +782,7 @@ static int winhttp_connect(
783
782
  }
784
783
 
785
784
  /* Prepare host */
786
- if (git__utf8_to_16_alloc(&wide_host, host) < 0) {
785
+ if (git_utf8_to_16_alloc(&wide_host, host) < 0) {
787
786
  git_error_set(GIT_ERROR_OS, "unable to convert host to wide characters");
788
787
  goto on_error;
789
788
  }
@@ -792,7 +791,7 @@ static int winhttp_connect(
792
791
  if (git_http__user_agent(&ua) < 0)
793
792
  goto on_error;
794
793
 
795
- if (git__utf8_to_16_alloc(&wide_ua, git_str_cstr(&ua)) < 0) {
794
+ if (git_utf8_to_16_alloc(&wide_ua, git_str_cstr(&ua)) < 0) {
796
795
  git_error_set(GIT_ERROR_OS, "unable to convert host to wide characters");
797
796
  goto on_error;
798
797
  }
@@ -1182,7 +1181,7 @@ replay:
1182
1181
  }
1183
1182
 
1184
1183
  /* Convert the Location header to UTF-8 */
1185
- if (git__utf16_to_8_alloc(&location8, location) < 0) {
1184
+ if (git_utf8_from_16_alloc(&location8, location) < 0) {
1186
1185
  git_error_set(GIT_ERROR_OS, "failed to convert Location header to UTF-8");
1187
1186
  git__free(location);
1188
1187
  return -1;
@@ -1254,7 +1253,7 @@ replay:
1254
1253
  else
1255
1254
  p_snprintf(expected_content_type_8, MAX_CONTENT_TYPE_LEN, "application/x-git-%s-advertisement", s->service);
1256
1255
 
1257
- if (git__utf8_to_16(expected_content_type, MAX_CONTENT_TYPE_LEN, expected_content_type_8) < 0) {
1256
+ if (git_utf8_to_16(expected_content_type, MAX_CONTENT_TYPE_LEN, expected_content_type_8) < 0) {
1258
1257
  git_error_set(GIT_ERROR_OS, "failed to convert expected content-type to wide characters");
1259
1258
  return -1;
1260
1259
  }
@@ -71,12 +71,16 @@ const git_tree_cache *git_tree_cache_get(const git_tree_cache *tree, const char
71
71
  }
72
72
  }
73
73
 
74
- static int read_tree_internal(git_tree_cache **out,
75
- const char **buffer_in, const char *buffer_end,
76
- git_pool *pool)
74
+ static int read_tree_internal(
75
+ git_tree_cache **out,
76
+ const char **buffer_in,
77
+ const char *buffer_end,
78
+ git_oid_t oid_type,
79
+ git_pool *pool)
77
80
  {
78
81
  git_tree_cache *tree = NULL;
79
82
  const char *name_start, *buffer;
83
+ size_t oid_size = git_oid_size(oid_type);
80
84
  int count;
81
85
 
82
86
  buffer = name_start = *buffer_in;
@@ -87,7 +91,7 @@ static int read_tree_internal(git_tree_cache **out,
87
91
  if (++buffer >= buffer_end)
88
92
  goto corrupted;
89
93
 
90
- if (git_tree_cache_new(&tree, name_start, pool) < 0)
94
+ if (git_tree_cache_new(&tree, name_start, oid_type, pool) < 0)
91
95
  return -1;
92
96
 
93
97
  /* Blank-terminated ASCII decimal number of entries in this tree */
@@ -108,14 +112,14 @@ static int read_tree_internal(git_tree_cache **out,
108
112
  if (*buffer != '\n' || ++buffer > buffer_end)
109
113
  goto corrupted;
110
114
 
111
- /* The SHA1 is only there if it's not invalidated */
115
+ /* The OID is only there if it's not invalidated */
112
116
  if (tree->entry_count >= 0) {
113
117
  /* 160-bit SHA-1 for this tree and it's children */
114
- if (buffer + GIT_OID_SHA1_SIZE > buffer_end)
118
+ if (buffer + oid_size > buffer_end)
115
119
  goto corrupted;
116
120
 
117
- git_oid__fromraw(&tree->oid, (const unsigned char *)buffer, GIT_OID_SHA1);
118
- buffer += GIT_OID_SHA1_SIZE;
121
+ git_oid__fromraw(&tree->oid, (const unsigned char *)buffer, oid_type);
122
+ buffer += oid_size;
119
123
  }
120
124
 
121
125
  /* Parse children: */
@@ -130,7 +134,7 @@ static int read_tree_internal(git_tree_cache **out,
130
134
  memset(tree->children, 0x0, bufsize);
131
135
 
132
136
  for (i = 0; i < tree->children_count; ++i) {
133
- if (read_tree_internal(&tree->children[i], &buffer, buffer_end, pool) < 0)
137
+ if (read_tree_internal(&tree->children[i], &buffer, buffer_end, oid_type, pool) < 0)
134
138
  goto corrupted;
135
139
  }
136
140
  }
@@ -144,11 +148,16 @@ static int read_tree_internal(git_tree_cache **out,
144
148
  return -1;
145
149
  }
146
150
 
147
- int git_tree_cache_read(git_tree_cache **tree, const char *buffer, size_t buffer_size, git_pool *pool)
151
+ int git_tree_cache_read(
152
+ git_tree_cache **tree,
153
+ const char *buffer,
154
+ size_t buffer_size,
155
+ git_oid_t oid_type,
156
+ git_pool *pool)
148
157
  {
149
158
  const char *buffer_end = buffer + buffer_size;
150
159
 
151
- if (read_tree_internal(tree, &buffer, buffer_end, pool) < 0)
160
+ if (read_tree_internal(tree, &buffer, buffer_end, oid_type, pool) < 0)
152
161
  return -1;
153
162
 
154
163
  if (buffer < buffer_end) {
@@ -201,7 +210,7 @@ static int read_tree_recursive(git_tree_cache *cache, const git_tree *tree, git_
201
210
  continue;
202
211
  }
203
212
 
204
- if ((error = git_tree_cache_new(&cache->children[j], git_tree_entry_name(entry), pool)) < 0)
213
+ if ((error = git_tree_cache_new(&cache->children[j], git_tree_entry_name(entry), cache->oid_type, pool)) < 0)
205
214
  return error;
206
215
 
207
216
  if ((error = git_tree_lookup(&subtree, repo, git_tree_entry_id(entry))) < 0)
@@ -219,12 +228,12 @@ static int read_tree_recursive(git_tree_cache *cache, const git_tree *tree, git_
219
228
  return 0;
220
229
  }
221
230
 
222
- int git_tree_cache_read_tree(git_tree_cache **out, const git_tree *tree, git_pool *pool)
231
+ int git_tree_cache_read_tree(git_tree_cache **out, const git_tree *tree, git_oid_t oid_type, git_pool *pool)
223
232
  {
224
233
  int error;
225
234
  git_tree_cache *cache;
226
235
 
227
- if ((error = git_tree_cache_new(&cache, "", pool)) < 0)
236
+ if ((error = git_tree_cache_new(&cache, "", oid_type, pool)) < 0)
228
237
  return error;
229
238
 
230
239
  if ((error = read_tree_recursive(cache, tree, pool)) < 0)
@@ -234,7 +243,7 @@ int git_tree_cache_read_tree(git_tree_cache **out, const git_tree *tree, git_poo
234
243
  return 0;
235
244
  }
236
245
 
237
- int git_tree_cache_new(git_tree_cache **out, const char *name, git_pool *pool)
246
+ int git_tree_cache_new(git_tree_cache **out, const char *name, git_oid_t oid_type, git_pool *pool)
238
247
  {
239
248
  size_t name_len, alloc_size;
240
249
  git_tree_cache *tree;
@@ -248,6 +257,7 @@ int git_tree_cache_new(git_tree_cache **out, const char *name, git_pool *pool)
248
257
 
249
258
  memset(tree, 0x0, sizeof(git_tree_cache));
250
259
  /* NUL-terminated tree name */
260
+ tree->oid_type = oid_type;
251
261
  tree->namelen = name_len;
252
262
  memcpy(tree->name, name, name_len);
253
263
  tree->name[name_len] = '\0';
@@ -263,7 +273,7 @@ static void write_tree(git_str *out, git_tree_cache *tree)
263
273
  git_str_printf(out, "%s%c%"PRIdZ" %"PRIuZ"\n", tree->name, 0, tree->entry_count, tree->children_count);
264
274
 
265
275
  if (tree->entry_count != -1)
266
- git_str_put(out, (char *)&tree->oid.id, GIT_OID_SHA1_SIZE);
276
+ git_str_put(out, (char *)&tree->oid.id, git_oid_size(tree->oid_type));
267
277
 
268
278
  for (i = 0; i < tree->children_count; i++)
269
279
  write_tree(out, tree->children[i]);