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
@@ -88,7 +88,7 @@ static int xdl_cleanup_merge(xdmerge_t *c)
88
88
  if (c->mode == 0)
89
89
  count++;
90
90
  next_c = c->next;
91
- xdl_free(c);
91
+ free(c);
92
92
  }
93
93
  return count;
94
94
  }
@@ -456,7 +456,7 @@ static void xdl_merge_two_conflicts(xdmerge_t *m)
456
456
  m->chg1 = next_m->i1 + next_m->chg1 - m->i1;
457
457
  m->chg2 = next_m->i2 + next_m->chg2 - m->i2;
458
458
  m->next = next_m->next;
459
- xdl_free(next_m);
459
+ free(next_m);
460
460
  }
461
461
 
462
462
  /*
@@ -684,42 +684,42 @@ static int xdl_do_merge(xdfenv_t *xe1, xdchange_t *xscr1,
684
684
  int xdl_merge(mmfile_t *orig, mmfile_t *mf1, mmfile_t *mf2,
685
685
  xmparam_t const *xmp, mmbuffer_t *result)
686
686
  {
687
- xdchange_t *xscr1, *xscr2;
687
+ xdchange_t *xscr1 = NULL, *xscr2 = NULL;
688
688
  xdfenv_t xe1, xe2;
689
- int status;
689
+ int status = -1;
690
690
  xpparam_t const *xpp = &xmp->xpp;
691
691
 
692
692
  result->ptr = NULL;
693
693
  result->size = 0;
694
694
 
695
- if (xdl_do_diff(orig, mf1, xpp, &xe1) < 0) {
695
+ if (xdl_do_diff(orig, mf1, xpp, &xe1) < 0)
696
696
  return -1;
697
- }
698
- if (xdl_do_diff(orig, mf2, xpp, &xe2) < 0) {
699
- xdl_free_env(&xe1);
700
- return -1;
701
- }
697
+
698
+ if (xdl_do_diff(orig, mf2, xpp, &xe2) < 0)
699
+ goto free_xe1; /* avoid double free of xe2 */
700
+
702
701
  if (xdl_change_compact(&xe1.xdf1, &xe1.xdf2, xpp->flags) < 0 ||
703
702
  xdl_change_compact(&xe1.xdf2, &xe1.xdf1, xpp->flags) < 0 ||
704
- xdl_build_script(&xe1, &xscr1) < 0) {
705
- xdl_free_env(&xe1);
706
- return -1;
707
- }
703
+ xdl_build_script(&xe1, &xscr1) < 0)
704
+ goto out;
705
+
708
706
  if (xdl_change_compact(&xe2.xdf1, &xe2.xdf2, xpp->flags) < 0 ||
709
707
  xdl_change_compact(&xe2.xdf2, &xe2.xdf1, xpp->flags) < 0 ||
710
- xdl_build_script(&xe2, &xscr2) < 0) {
711
- xdl_free_script(xscr1);
712
- xdl_free_env(&xe1);
713
- xdl_free_env(&xe2);
714
- return -1;
715
- }
716
- status = 0;
708
+ xdl_build_script(&xe2, &xscr2) < 0)
709
+ goto out;
710
+
717
711
  if (!xscr1) {
718
712
  result->ptr = xdl_malloc(mf2->size);
713
+ if (!result->ptr)
714
+ goto out;
715
+ status = 0;
719
716
  memcpy(result->ptr, mf2->ptr, mf2->size);
720
717
  result->size = mf2->size;
721
718
  } else if (!xscr2) {
722
719
  result->ptr = xdl_malloc(mf1->size);
720
+ if (!result->ptr)
721
+ goto out;
722
+ status = 0;
723
723
  memcpy(result->ptr, mf1->ptr, mf1->size);
724
724
  result->size = mf1->size;
725
725
  } else {
@@ -727,11 +727,13 @@ int xdl_merge(mmfile_t *orig, mmfile_t *mf1, mmfile_t *mf2,
727
727
  &xe2, xscr2,
728
728
  xmp, result);
729
729
  }
730
+ out:
730
731
  xdl_free_script(xscr1);
731
732
  xdl_free_script(xscr2);
732
733
 
733
- xdl_free_env(&xe1);
734
734
  xdl_free_env(&xe2);
735
+ free_xe1:
736
+ xdl_free_env(&xe1);
735
737
 
736
738
  return status;
737
739
  }
@@ -69,7 +69,6 @@ struct hashmap {
69
69
  } *entries, *first, *last;
70
70
  /* were common records found? */
71
71
  unsigned long has_matches;
72
- mmfile_t *file1, *file2;
73
72
  xdfenv_t *env;
74
73
  xpparam_t const *xpp;
75
74
  };
@@ -139,23 +138,17 @@ static void insert_record(xpparam_t const *xpp, int line, struct hashmap *map,
139
138
  *
140
139
  * It is assumed that env has been prepared using xdl_prepare().
141
140
  */
142
- static int fill_hashmap(mmfile_t *file1, mmfile_t *file2,
143
- xpparam_t const *xpp, xdfenv_t *env,
141
+ static int fill_hashmap(xpparam_t const *xpp, xdfenv_t *env,
144
142
  struct hashmap *result,
145
143
  int line1, int count1, int line2, int count2)
146
144
  {
147
- result->file1 = file1;
148
- result->file2 = file2;
149
145
  result->xpp = xpp;
150
146
  result->env = env;
151
147
 
152
148
  /* We know exactly how large we want the hash map */
153
149
  result->alloc = count1 * 2;
154
- result->entries = (struct entry *)
155
- xdl_malloc(result->alloc * sizeof(struct entry));
156
- if (!result->entries)
150
+ if (!XDL_CALLOC_ARRAY(result->entries, result->alloc))
157
151
  return -1;
158
- memset(result->entries, 0, result->alloc * sizeof(struct entry));
159
152
 
160
153
  /* First, fill with entries from the first file */
161
154
  while (count1--)
@@ -198,9 +191,9 @@ static int binary_search(struct entry **sequence, int longest,
198
191
  * item per sequence length: the sequence with the smallest last
199
192
  * element (in terms of line2).
200
193
  */
201
- static struct entry *find_longest_common_sequence(struct hashmap *map)
194
+ static int find_longest_common_sequence(struct hashmap *map, struct entry **res)
202
195
  {
203
- struct entry **sequence = xdl_malloc(map->nr * sizeof(struct entry *));
196
+ struct entry **sequence;
204
197
  int longest = 0, i;
205
198
  struct entry *entry;
206
199
 
@@ -211,6 +204,9 @@ static struct entry *find_longest_common_sequence(struct hashmap *map)
211
204
  */
212
205
  int anchor_i = -1;
213
206
 
207
+ if (!XDL_ALLOC_ARRAY(sequence, map->nr))
208
+ return -1;
209
+
214
210
  for (entry = map->first; entry; entry = entry->next) {
215
211
  if (!entry->line2 || entry->line2 == NON_UNIQUE)
216
212
  continue;
@@ -230,8 +226,9 @@ static struct entry *find_longest_common_sequence(struct hashmap *map)
230
226
 
231
227
  /* No common unique lines were found */
232
228
  if (!longest) {
229
+ *res = NULL;
233
230
  xdl_free(sequence);
234
- return NULL;
231
+ return 0;
235
232
  }
236
233
 
237
234
  /* Iterate starting at the last element, adjusting the "next" members */
@@ -241,8 +238,9 @@ static struct entry *find_longest_common_sequence(struct hashmap *map)
241
238
  entry->previous->next = entry;
242
239
  entry = entry->previous;
243
240
  }
241
+ *res = entry;
244
242
  xdl_free(sequence);
245
- return entry;
243
+ return 0;
246
244
  }
247
245
 
248
246
  static int match(struct hashmap *map, int line1, int line2)
@@ -252,8 +250,7 @@ static int match(struct hashmap *map, int line1, int line2)
252
250
  return record1->ha == record2->ha;
253
251
  }
254
252
 
255
- static int patience_diff(mmfile_t *file1, mmfile_t *file2,
256
- xpparam_t const *xpp, xdfenv_t *env,
253
+ static int patience_diff(xpparam_t const *xpp, xdfenv_t *env,
257
254
  int line1, int count1, int line2, int count2);
258
255
 
259
256
  static int walk_common_sequence(struct hashmap *map, struct entry *first,
@@ -284,8 +281,7 @@ static int walk_common_sequence(struct hashmap *map, struct entry *first,
284
281
 
285
282
  /* Recurse */
286
283
  if (next1 > line1 || next2 > line2) {
287
- if (patience_diff(map->file1, map->file2,
288
- map->xpp, map->env,
284
+ if (patience_diff(map->xpp, map->env,
289
285
  line1, next1 - line1,
290
286
  line2, next2 - line2))
291
287
  return -1;
@@ -324,8 +320,7 @@ static int fall_back_to_classic_diff(struct hashmap *map,
324
320
  *
325
321
  * This function assumes that env was prepared with xdl_prepare_env().
326
322
  */
327
- static int patience_diff(mmfile_t *file1, mmfile_t *file2,
328
- xpparam_t const *xpp, xdfenv_t *env,
323
+ static int patience_diff(xpparam_t const *xpp, xdfenv_t *env,
329
324
  int line1, int count1, int line2, int count2)
330
325
  {
331
326
  struct hashmap map;
@@ -344,7 +339,7 @@ static int patience_diff(mmfile_t *file1, mmfile_t *file2,
344
339
  }
345
340
 
346
341
  memset(&map, 0, sizeof(map));
347
- if (fill_hashmap(file1, file2, xpp, env, &map,
342
+ if (fill_hashmap(xpp, env, &map,
348
343
  line1, count1, line2, count2))
349
344
  return -1;
350
345
 
@@ -358,25 +353,21 @@ static int patience_diff(mmfile_t *file1, mmfile_t *file2,
358
353
  return 0;
359
354
  }
360
355
 
361
- first = find_longest_common_sequence(&map);
356
+ result = find_longest_common_sequence(&map, &first);
357
+ if (result)
358
+ goto out;
362
359
  if (first)
363
360
  result = walk_common_sequence(&map, first,
364
361
  line1, count1, line2, count2);
365
362
  else
366
363
  result = fall_back_to_classic_diff(&map,
367
364
  line1, count1, line2, count2);
368
-
365
+ out:
369
366
  xdl_free(map.entries);
370
367
  return result;
371
368
  }
372
369
 
373
- int xdl_do_patience_diff(mmfile_t *file1, mmfile_t *file2,
374
- xpparam_t const *xpp, xdfenv_t *env)
370
+ int xdl_do_patience_diff(xpparam_t const *xpp, xdfenv_t *env)
375
371
  {
376
- if (xdl_prepare_env(file1, file2, xpp, env) < 0)
377
- return -1;
378
-
379
- /* environment is cleaned up in xdl_diff() */
380
- return patience_diff(file1, file2, xpp, env,
381
- 1, env->xdf1.nrec, 1, env->xdf2.nrec);
372
+ return patience_diff(xpp, env, 1, env->xdf1.nrec, 1, env->xdf2.nrec);
382
373
  }
@@ -78,15 +78,14 @@ static int xdl_init_classifier(xdlclassifier_t *cf, long size, long flags) {
78
78
 
79
79
  return -1;
80
80
  }
81
- if (!(cf->rchash = (xdlclass_t **) xdl_malloc(cf->hsize * sizeof(xdlclass_t *)))) {
81
+ if (!XDL_CALLOC_ARRAY(cf->rchash, cf->hsize)) {
82
82
 
83
83
  xdl_cha_free(&cf->ncha);
84
84
  return -1;
85
85
  }
86
- memset(cf->rchash, 0, cf->hsize * sizeof(xdlclass_t *));
87
86
 
88
87
  cf->alloc = size;
89
- if (!(cf->rcrecs = (xdlclass_t **) xdl_malloc(cf->alloc * sizeof(xdlclass_t *)))) {
88
+ if (!XDL_ALLOC_ARRAY(cf->rcrecs, cf->alloc)) {
90
89
 
91
90
  xdl_free(cf->rchash);
92
91
  xdl_cha_free(&cf->ncha);
@@ -112,7 +111,6 @@ static int xdl_classify_record(unsigned int pass, xdlclassifier_t *cf, xrecord_t
112
111
  long hi;
113
112
  char const *line;
114
113
  xdlclass_t *rcrec;
115
- xdlclass_t **rcrecs;
116
114
 
117
115
  line = rec->ptr;
118
116
  hi = (long) XDL_HASHLONG(rec->ha, cf->hbits);
@@ -128,14 +126,8 @@ static int xdl_classify_record(unsigned int pass, xdlclassifier_t *cf, xrecord_t
128
126
  return -1;
129
127
  }
130
128
  rcrec->idx = cf->count++;
131
- if (cf->count > cf->alloc) {
132
- cf->alloc *= 2;
133
- if (!(rcrecs = (xdlclass_t **) xdl_realloc(cf->rcrecs, cf->alloc * sizeof(xdlclass_t *)))) {
134
-
129
+ if (XDL_ALLOC_GROW(cf->rcrecs, cf->count, cf->alloc))
135
130
  return -1;
136
- }
137
- cf->rcrecs = rcrecs;
138
- }
139
131
  cf->rcrecs[rcrec->idx] = rcrec;
140
132
  rcrec->line = line;
141
133
  rcrec->size = rec->size;
@@ -164,7 +156,7 @@ static int xdl_prepare_ctx(unsigned int pass, mmfile_t *mf, long narec, xpparam_
164
156
  unsigned long hav;
165
157
  char const *blk, *cur, *top, *prev;
166
158
  xrecord_t *crec;
167
- xrecord_t **recs, **rrecs;
159
+ xrecord_t **recs;
168
160
  xrecord_t **rhash;
169
161
  unsigned long *ha;
170
162
  char *rchg;
@@ -178,26 +170,21 @@ static int xdl_prepare_ctx(unsigned int pass, mmfile_t *mf, long narec, xpparam_
178
170
 
179
171
  if (xdl_cha_init(&xdf->rcha, sizeof(xrecord_t), narec / 4 + 1) < 0)
180
172
  goto abort;
181
- if (!(recs = (xrecord_t **) xdl_malloc(narec * sizeof(xrecord_t *))))
173
+ if (!XDL_ALLOC_ARRAY(recs, narec))
182
174
  goto abort;
183
175
 
184
176
  hbits = xdl_hashbits((unsigned int) narec);
185
177
  hsize = 1 << hbits;
186
- if (!(rhash = (xrecord_t **) xdl_malloc(hsize * sizeof(xrecord_t *))))
178
+ if (!XDL_CALLOC_ARRAY(rhash, hsize))
187
179
  goto abort;
188
- memset(rhash, 0, hsize * sizeof(xrecord_t *));
189
180
 
190
181
  nrec = 0;
191
- if ((cur = blk = xdl_mmfile_first(mf, &bsize)) != NULL) {
182
+ if ((cur = blk = xdl_mmfile_first(mf, &bsize))) {
192
183
  for (top = blk + bsize; cur < top; ) {
193
184
  prev = cur;
194
185
  hav = xdl_hash_record(&cur, top, xpp->flags);
195
- if (nrec >= narec) {
196
- narec *= 2;
197
- if (!(rrecs = (xrecord_t **) xdl_realloc(recs, narec * sizeof(xrecord_t *))))
198
- goto abort;
199
- recs = rrecs;
200
- }
186
+ if (XDL_ALLOC_GROW(recs, nrec + 1, narec))
187
+ goto abort;
201
188
  if (!(crec = xdl_cha_alloc(&xdf->rcha)))
202
189
  goto abort;
203
190
  crec->ptr = prev;
@@ -209,15 +196,14 @@ static int xdl_prepare_ctx(unsigned int pass, mmfile_t *mf, long narec, xpparam_
209
196
  }
210
197
  }
211
198
 
212
- if (!(rchg = (char *) xdl_malloc((nrec + 2) * sizeof(char))))
199
+ if (!XDL_CALLOC_ARRAY(rchg, nrec + 2))
213
200
  goto abort;
214
- memset(rchg, 0, (nrec + 2) * sizeof(char));
215
201
 
216
202
  if ((XDF_DIFF_ALG(xpp->flags) != XDF_PATIENCE_DIFF) &&
217
203
  (XDF_DIFF_ALG(xpp->flags) != XDF_HISTOGRAM_DIFF)) {
218
- if (!(rindex = xdl_malloc((nrec + 1) * sizeof(*rindex))))
204
+ if (!XDL_ALLOC_ARRAY(rindex, nrec + 1))
219
205
  goto abort;
220
- if (!(ha = xdl_malloc((nrec + 1) * sizeof(*ha))))
206
+ if (!XDL_ALLOC_ARRAY(ha, nrec + 1))
221
207
  goto abort;
222
208
  }
223
209
 
@@ -383,11 +369,8 @@ static int xdl_cleanup_records(xdlclassifier_t *cf, xdfile_t *xdf1, xdfile_t *xd
383
369
  xdlclass_t *rcrec;
384
370
  char *dis, *dis1, *dis2;
385
371
 
386
- if (!(dis = (char *) xdl_malloc(xdf1->nrec + xdf2->nrec + 2))) {
387
-
372
+ if (!XDL_CALLOC_ARRAY(dis, xdf1->nrec + xdf2->nrec + 2))
388
373
  return -1;
389
- }
390
- memset(dis, 0, xdf1->nrec + xdf2->nrec + 2);
391
374
  dis1 = dis;
392
375
  dis2 = dis1 + xdf1->nrec + 1;
393
376
 
@@ -122,7 +122,7 @@ long xdl_guess_lines(mmfile_t *mf, long sample) {
122
122
  long nl = 0, size, tsize = 0;
123
123
  char const *data, *cur, *top;
124
124
 
125
- if ((cur = data = xdl_mmfile_first(mf, &size)) != NULL) {
125
+ if ((cur = data = xdl_mmfile_first(mf, &size))) {
126
126
  for (top = data + size; nl < sample && cur < top; ) {
127
127
  nl++;
128
128
  if (!(cur = memchr(cur, '\n', top - cur)))
@@ -432,3 +432,20 @@ int xdl_fall_back_diff(xdfenv_t *diff_env, xpparam_t const *xpp,
432
432
 
433
433
  return 0;
434
434
  }
435
+
436
+ void* xdl_alloc_grow_helper(void *p, long nr, long *alloc, size_t size)
437
+ {
438
+ void *tmp = NULL;
439
+ size_t n = ((LONG_MAX - 16) / 2 >= *alloc) ? 2 * *alloc + 16 : LONG_MAX;
440
+ if (nr > n)
441
+ n = nr;
442
+ if (SIZE_MAX / size >= n)
443
+ tmp = xdl_realloc(p, n * size);
444
+ if (tmp) {
445
+ *alloc = n;
446
+ } else {
447
+ xdl_free(p);
448
+ *alloc = 0;
449
+ }
450
+ return tmp;
451
+ }
@@ -42,6 +42,7 @@ int xdl_emit_hunk_hdr(long s1, long c1, long s2, long c2,
42
42
  int xdl_fall_back_diff(xdfenv_t *diff_env, xpparam_t const *xpp,
43
43
  int line1, int count1, int line2, int count2);
44
44
 
45
-
45
+ /* Do not call this function, use XDL_ALLOC_GROW instead */
46
+ void* xdl_alloc_grow_helper(void* p, long nr, long* alloc, size_t size);
46
47
 
47
48
  #endif /* #if !defined(XUTILS_H) */
@@ -224,7 +224,11 @@ typedef enum {
224
224
  GIT_OPT_GET_OWNER_VALIDATION,
225
225
  GIT_OPT_SET_OWNER_VALIDATION,
226
226
  GIT_OPT_GET_HOMEDIR,
227
- GIT_OPT_SET_HOMEDIR
227
+ GIT_OPT_SET_HOMEDIR,
228
+ GIT_OPT_SET_SERVER_CONNECT_TIMEOUT,
229
+ GIT_OPT_GET_SERVER_CONNECT_TIMEOUT,
230
+ GIT_OPT_SET_SERVER_TIMEOUT,
231
+ GIT_OPT_GET_SERVER_TIMEOUT
228
232
  } git_libgit2_opt_t;
229
233
 
230
234
  /**
@@ -480,6 +484,27 @@ typedef enum {
480
484
  * >
481
485
  * > - `path` directory of home directory.
482
486
  *
487
+ * opts(GIT_OPT_GET_SERVER_CONNECT_TIMEOUT, int *timeout)
488
+ * > Gets the timeout (in milliseconds) to attempt connections to
489
+ * > a remote server.
490
+ *
491
+ * opts(GIT_OPT_SET_SERVER_CONNECT_TIMEOUT, int timeout)
492
+ * > Sets the timeout (in milliseconds) to attempt connections to
493
+ * > a remote server. This is supported only for HTTP(S) connections
494
+ * > and is not supported by SSH. Set to 0 to use the system default.
495
+ * > Note that this may not be able to be configured longer than the
496
+ * > system default, typically 75 seconds.
497
+ *
498
+ * opts(GIT_OPT_GET_SERVER_TIMEOUT, int *timeout)
499
+ * > Gets the timeout (in milliseconds) for reading from and writing
500
+ * > to a remote server.
501
+ *
502
+ * opts(GIT_OPT_SET_SERVER_TIMEOUT, int timeout)
503
+ * > Sets the timeout (in milliseconds) for reading from and writing
504
+ * > to a remote server. This is supported only for HTTP(S)
505
+ * > connections and is not supported by SSH. Set to 0 to use the
506
+ * > system default.
507
+ *
483
508
  * @param option Option key
484
509
  * @param ... value to set the option
485
510
  * @return 0 on success, <0 on failure
@@ -421,6 +421,22 @@ typedef struct {
421
421
  */
422
422
  uint32_t interhunk_lines;
423
423
 
424
+ /**
425
+ * The object ID type to emit in diffs; this is used by functions
426
+ * that operate without a repository - namely `git_diff_buffers`,
427
+ * or `git_diff_blobs` and `git_diff_blob_to_buffer` when one blob
428
+ * is `NULL`.
429
+ *
430
+ * This may be omitted (set to `0`). If a repository is available,
431
+ * the object ID format of the repository will be used. If no
432
+ * repository is available then the default is `GIT_OID_SHA`.
433
+ *
434
+ * If this is specified and a repository is available, then the
435
+ * specified `oid_type` must match the repository's object ID
436
+ * format.
437
+ */
438
+ git_oid_t oid_type;
439
+
424
440
  /**
425
441
  * The abbreviation length to use when formatting object ids.
426
442
  * Defaults to the value of 'core.abbrev' from the config, or 7 if unset.
@@ -1153,9 +1169,8 @@ GIT_EXTERN(int) git_diff_to_buf(
1153
1169
 
1154
1170
  /**@}*/
1155
1171
 
1156
-
1157
1172
  /*
1158
- * Misc
1173
+ * Low-level file comparison, invoking callbacks per difference.
1159
1174
  */
1160
1175
 
1161
1176
  /**
@@ -1271,6 +1286,25 @@ GIT_EXTERN(int) git_diff_buffers(
1271
1286
  git_diff_line_cb line_cb,
1272
1287
  void *payload);
1273
1288
 
1289
+ /* Patch file parsing. */
1290
+
1291
+ /**
1292
+ * Options for parsing a diff / patch file.
1293
+ */
1294
+ typedef struct {
1295
+ unsigned int version;
1296
+ git_oid_t oid_type;
1297
+ } git_diff_parse_options;
1298
+
1299
+ /* The current version of the diff parse options structure */
1300
+ #define GIT_DIFF_PARSE_OPTIONS_VERSION 1
1301
+
1302
+ /* Stack initializer for diff parse options. Alternatively use
1303
+ * `git_diff_parse_options_init` programmatic initialization.
1304
+ */
1305
+ #define GIT_DIFF_PARSE_OPTIONS_INIT \
1306
+ { GIT_DIFF_PARSE_OPTIONS_VERSION, GIT_OID_DEFAULT }
1307
+
1274
1308
  /**
1275
1309
  * Read the contents of a git patch file into a `git_diff` object.
1276
1310
  *
@@ -1293,7 +1327,11 @@ GIT_EXTERN(int) git_diff_buffers(
1293
1327
  GIT_EXTERN(int) git_diff_from_buffer(
1294
1328
  git_diff **out,
1295
1329
  const char *content,
1296
- size_t content_len);
1330
+ size_t content_len
1331
+ #ifdef GIT_EXPERIMENTAL_SHA256
1332
+ , git_diff_parse_options *opts
1333
+ #endif
1334
+ );
1297
1335
 
1298
1336
  /**
1299
1337
  * This is an opaque structure which is allocated by `git_diff_get_stats`.
@@ -58,7 +58,8 @@ typedef enum {
58
58
  GIT_EMISMATCH = -33, /**< Hashsum mismatch in object */
59
59
  GIT_EINDEXDIRTY = -34, /**< Unsaved changes in the index would be overwritten */
60
60
  GIT_EAPPLYFAIL = -35, /**< Patch application failed */
61
- GIT_EOWNER = -36 /**< The object is not owned by the current user */
61
+ GIT_EOWNER = -36, /**< The object is not owned by the current user */
62
+ GIT_TIMEOUT = -37 /**< The operation timed out */
62
63
  } git_error_code;
63
64
 
64
65
  /**
@@ -109,7 +110,8 @@ typedef enum {
109
110
  GIT_ERROR_WORKTREE,
110
111
  GIT_ERROR_SHA,
111
112
  GIT_ERROR_HTTP,
112
- GIT_ERROR_INTERNAL
113
+ GIT_ERROR_INTERNAL,
114
+ GIT_ERROR_GRAFTS
113
115
  } git_error_t;
114
116
 
115
117
  /**
@@ -184,7 +184,12 @@ typedef enum {
184
184
  * @param index_path the path to the index file in disk
185
185
  * @return 0 or an error code
186
186
  */
187
+
188
+ #ifdef GIT_EXPERIMENTAL_SHA256
189
+ GIT_EXTERN(int) git_index_open(git_index **out, const char *index_path, git_oid_t oid_type);
190
+ #else
187
191
  GIT_EXTERN(int) git_index_open(git_index **out, const char *index_path);
192
+ #endif
188
193
 
189
194
  /**
190
195
  * Create an in-memory index object.
@@ -197,7 +202,11 @@ GIT_EXTERN(int) git_index_open(git_index **out, const char *index_path);
197
202
  * @param out the pointer for the new index
198
203
  * @return 0 or an error code
199
204
  */
205
+ #ifdef GIT_EXPERIMENTAL_SHA256
206
+ GIT_EXTERN(int) git_index_new(git_index **out, git_oid_t oid_type);
207
+ #else
200
208
  GIT_EXTERN(int) git_index_new(git_index **out);
209
+ #endif
201
210
 
202
211
  /**
203
212
  * Free an existing index object.
@@ -225,7 +225,7 @@ GIT_EXTERN(int) git_oid_pathfmt(char *out, const git_oid *id);
225
225
  * concurrent calls of the function.
226
226
  *
227
227
  * @param oid The oid structure to format
228
- * @return the c-string
228
+ * @return the c-string or NULL on failure
229
229
  */
230
230
  GIT_EXTERN(char *) git_oid_tostr_s(const git_oid *oid);
231
231
 
@@ -702,6 +702,15 @@ typedef enum {
702
702
  GIT_REMOTE_DOWNLOAD_TAGS_ALL
703
703
  } git_remote_autotag_option_t;
704
704
 
705
+ /** Constants for fetch depth (shallowness of fetch). */
706
+ typedef enum {
707
+ /** The fetch is "full" (not shallow). This is the default. */
708
+ GIT_FETCH_DEPTH_FULL = 0,
709
+
710
+ /** The fetch should "unshallow" and fetch missing data. */
711
+ GIT_FETCH_DEPTH_UNSHALLOW = 2147483647
712
+ } git_fetch_depth_t;
713
+
705
714
  /**
706
715
  * Fetch options structure.
707
716
  *
@@ -743,6 +752,15 @@ typedef struct {
743
752
  */
744
753
  git_proxy_options proxy_opts;
745
754
 
755
+ /**
756
+ * Depth of the fetch to perform, or `GIT_FETCH_DEPTH_FULL`
757
+ * (or `0`) for full history, or `GIT_FETCH_DEPTH_UNSHALLOW`
758
+ * to "unshallow" a shallow repository.
759
+ *
760
+ * The default is full (`GIT_FETCH_DEPTH_FULL` or `0`).
761
+ */
762
+ int depth;
763
+
746
764
  /**
747
765
  * Whether to allow off-site redirects. If this is not
748
766
  * specified, the `http.followRedirects` configuration setting
@@ -56,9 +56,19 @@ GIT_EXTERN(int) git_repository_open_from_worktree(git_repository **out, git_work
56
56
  *
57
57
  * @param out pointer to the repo
58
58
  * @param odb the object database to wrap
59
+ * @param oid_type the oid type of the object database
59
60
  * @return 0 or an error code
60
61
  */
61
- GIT_EXTERN(int) git_repository_wrap_odb(git_repository **out, git_odb *odb);
62
+ #ifdef GIT_EXPERIMENTAL_SHA256
63
+ GIT_EXTERN(int) git_repository_wrap_odb(
64
+ git_repository **out,
65
+ git_odb *odb,
66
+ git_oid_t oid_type);
67
+ #else
68
+ GIT_EXTERN(int) git_repository_wrap_odb(
69
+ git_repository **out,
70
+ git_odb *odb);
71
+ #endif
62
72
 
63
73
  /**
64
74
  * Look for a git repository and copy its path in the given buffer.
@@ -536,7 +546,7 @@ GIT_EXTERN(const char *) git_repository_workdir(const git_repository *repo);
536
546
 
537
547
  /**
538
548
  * Get the path of the shared common directory for this repository.
539
- *
549
+ *
540
550
  * If the repository is bare, it is the root directory for the repository.
541
551
  * If the repository is a worktree, it is the parent repo's gitdir.
542
552
  * Otherwise, it is the gitdir.
@@ -24,28 +24,6 @@ typedef struct {
24
24
  /** Allocate `n` bytes of memory */
25
25
  void * GIT_CALLBACK(gmalloc)(size_t n, const char *file, int line);
26
26
 
27
- /**
28
- * Allocate memory for an array of `nelem` elements, where each element
29
- * has a size of `elsize`. Returned memory shall be initialized to
30
- * all-zeroes
31
- */
32
- void * GIT_CALLBACK(gcalloc)(size_t nelem, size_t elsize, const char *file, int line);
33
-
34
- /** Allocate memory for the string `str` and duplicate its contents. */
35
- char * GIT_CALLBACK(gstrdup)(const char *str, const char *file, int line);
36
-
37
- /**
38
- * Equivalent to the `gstrdup` function, but only duplicating at most
39
- * `n + 1` bytes
40
- */
41
- char * GIT_CALLBACK(gstrndup)(const char *str, size_t n, const char *file, int line);
42
-
43
- /**
44
- * Equivalent to `gstrndup`, but will always duplicate exactly `n` bytes
45
- * of `str`. Thus, out of bounds reads at `str` may happen.
46
- */
47
- char * GIT_CALLBACK(gsubstrdup)(const char *str, size_t n, const char *file, int line);
48
-
49
27
  /**
50
28
  * This function shall deallocate the old object `ptr` and return a
51
29
  * pointer to a new object that has the size specified by `size`. In
@@ -53,18 +31,6 @@ typedef struct {
53
31
  */
54
32
  void * GIT_CALLBACK(grealloc)(void *ptr, size_t size, const char *file, int line);
55
33
 
56
- /**
57
- * This function shall be equivalent to `grealloc`, but allocating
58
- * `neleme * elsize` bytes.
59
- */
60
- void * GIT_CALLBACK(greallocarray)(void *ptr, size_t nelem, size_t elsize, const char *file, int line);
61
-
62
- /**
63
- * This function shall allocate a new array of `nelem` elements, where
64
- * each element has a size of `elsize` bytes.
65
- */
66
- void * GIT_CALLBACK(gmallocarray)(size_t nelem, size_t elsize, const char *file, int line);
67
-
68
34
  /**
69
35
  * This function shall free the memory pointed to by `ptr`. In case
70
36
  * `ptr` is `NULL`, this shall be a no-op.