rugged 0.24.6.1 → 0.25.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (213) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +1 -1
  3. data/ext/rugged/extconf.rb +9 -2
  4. data/ext/rugged/rugged.c +85 -21
  5. data/ext/rugged/rugged.h +7 -21
  6. data/ext/rugged/rugged_backend.c +3 -20
  7. data/ext/rugged/rugged_blame.c +7 -24
  8. data/ext/rugged/rugged_blob.c +136 -59
  9. data/ext/rugged/rugged_branch.c +3 -20
  10. data/ext/rugged/rugged_branch_collection.c +3 -20
  11. data/ext/rugged/rugged_commit.c +251 -101
  12. data/ext/rugged/rugged_config.c +3 -20
  13. data/ext/rugged/rugged_cred.c +3 -20
  14. data/ext/rugged/rugged_diff.c +3 -20
  15. data/ext/rugged/rugged_diff_delta.c +3 -20
  16. data/ext/rugged/rugged_diff_hunk.c +3 -20
  17. data/ext/rugged/rugged_diff_line.c +3 -20
  18. data/ext/rugged/rugged_index.c +46 -229
  19. data/ext/rugged/rugged_note.c +3 -20
  20. data/ext/rugged/rugged_object.c +3 -20
  21. data/ext/rugged/rugged_patch.c +192 -34
  22. data/ext/rugged/rugged_rebase.c +90 -48
  23. data/ext/rugged/rugged_reference.c +4 -21
  24. data/ext/rugged/rugged_reference_collection.c +3 -20
  25. data/ext/rugged/rugged_remote.c +70 -42
  26. data/ext/rugged/rugged_remote_collection.c +3 -20
  27. data/ext/rugged/rugged_repo.c +50 -59
  28. data/ext/rugged/rugged_revwalk.c +4 -21
  29. data/ext/rugged/rugged_settings.c +3 -20
  30. data/ext/rugged/rugged_signature.c +3 -20
  31. data/ext/rugged/rugged_submodule.c +4 -21
  32. data/ext/rugged/rugged_submodule_collection.c +3 -20
  33. data/ext/rugged/rugged_tag.c +3 -20
  34. data/ext/rugged/rugged_tag_collection.c +3 -20
  35. data/ext/rugged/rugged_tree.c +189 -184
  36. data/lib/rugged/attributes.rb +5 -0
  37. data/lib/rugged/blob.rb +5 -0
  38. data/lib/rugged/branch.rb +6 -1
  39. data/lib/rugged/commit.rb +5 -0
  40. data/lib/rugged/console.rb +5 -0
  41. data/lib/rugged/credentials.rb +5 -0
  42. data/lib/rugged/diff/delta.rb +5 -0
  43. data/lib/rugged/diff/hunk.rb +5 -0
  44. data/lib/rugged/diff/line.rb +5 -0
  45. data/lib/rugged/diff.rb +5 -0
  46. data/lib/rugged/index.rb +120 -0
  47. data/lib/rugged/object.rb +5 -0
  48. data/lib/rugged/patch.rb +5 -0
  49. data/lib/rugged/reference.rb +5 -0
  50. data/lib/rugged/remote.rb +5 -0
  51. data/lib/rugged/repository.rb +9 -4
  52. data/lib/rugged/submodule_collection.rb +5 -0
  53. data/lib/rugged/tag.rb +5 -0
  54. data/lib/rugged/tree.rb +156 -1
  55. data/lib/rugged/version.rb +6 -1
  56. data/lib/rugged/walker.rb +5 -0
  57. data/lib/rugged.rb +5 -0
  58. data/vendor/libgit2/CMakeLists.txt +12 -2
  59. data/vendor/libgit2/include/git2/blob.h +39 -28
  60. data/vendor/libgit2/include/git2/commit.h +76 -0
  61. data/vendor/libgit2/include/git2/common.h +21 -1
  62. data/vendor/libgit2/include/git2/describe.h +5 -2
  63. data/vendor/libgit2/include/git2/diff.h +62 -7
  64. data/vendor/libgit2/include/git2/errors.h +2 -1
  65. data/vendor/libgit2/include/git2/index.h +25 -0
  66. data/vendor/libgit2/include/git2/merge.h +10 -1
  67. data/vendor/libgit2/include/git2/odb.h +47 -1
  68. data/vendor/libgit2/include/git2/pack.h +4 -4
  69. data/vendor/libgit2/include/git2/patch.h +1 -1
  70. data/vendor/libgit2/include/git2/proxy.h +92 -0
  71. data/vendor/libgit2/include/git2/refs.h +11 -0
  72. data/vendor/libgit2/include/git2/remote.h +21 -8
  73. data/vendor/libgit2/include/git2/repository.h +20 -1
  74. data/vendor/libgit2/include/git2/revwalk.h +4 -6
  75. data/vendor/libgit2/include/git2/signature.h +13 -0
  76. data/vendor/libgit2/include/git2/submodule.h +11 -3
  77. data/vendor/libgit2/include/git2/sys/merge.h +177 -0
  78. data/vendor/libgit2/include/git2/sys/odb_backend.h +11 -0
  79. data/vendor/libgit2/include/git2/sys/remote.h +16 -0
  80. data/vendor/libgit2/include/git2/sys/stream.h +2 -1
  81. data/vendor/libgit2/include/git2/sys/time.h +31 -0
  82. data/vendor/libgit2/include/git2/sys/transport.h +3 -1
  83. data/vendor/libgit2/include/git2/tag.h +9 -0
  84. data/vendor/libgit2/include/git2/transaction.h +9 -0
  85. data/vendor/libgit2/include/git2/tree.h +55 -0
  86. data/vendor/libgit2/include/git2/version.h +4 -4
  87. data/vendor/libgit2/include/git2.h +1 -0
  88. data/vendor/libgit2/src/annotated_commit.c +99 -80
  89. data/vendor/libgit2/src/annotated_commit.h +5 -2
  90. data/vendor/libgit2/src/apply.c +377 -0
  91. data/vendor/libgit2/src/apply.h +21 -0
  92. data/vendor/libgit2/src/array.h +0 -1
  93. data/vendor/libgit2/src/blob.c +71 -39
  94. data/vendor/libgit2/src/branch.c +7 -5
  95. data/vendor/libgit2/src/buffer.c +252 -20
  96. data/vendor/libgit2/src/buffer.h +8 -0
  97. data/vendor/libgit2/src/checkout.c +69 -42
  98. data/vendor/libgit2/src/clone.c +0 -8
  99. data/vendor/libgit2/src/commit.c +193 -49
  100. data/vendor/libgit2/src/commit_list.c +8 -3
  101. data/vendor/libgit2/src/commit_list.h +1 -0
  102. data/vendor/libgit2/src/common.h +2 -1
  103. data/vendor/libgit2/src/config.c +3 -3
  104. data/vendor/libgit2/src/config_file.c +20 -10
  105. data/vendor/libgit2/src/crlf.c +1 -0
  106. data/vendor/libgit2/src/curl_stream.c +106 -6
  107. data/vendor/libgit2/src/delta.c +238 -62
  108. data/vendor/libgit2/src/delta.h +79 -58
  109. data/vendor/libgit2/src/describe.c +1 -1
  110. data/vendor/libgit2/src/diff.c +32 -1554
  111. data/vendor/libgit2/src/diff.h +14 -122
  112. data/vendor/libgit2/src/diff_driver.c +4 -6
  113. data/vendor/libgit2/src/diff_file.c +3 -0
  114. data/vendor/libgit2/src/diff_generate.c +1613 -0
  115. data/vendor/libgit2/src/diff_generate.h +123 -0
  116. data/vendor/libgit2/src/diff_parse.c +101 -0
  117. data/vendor/libgit2/src/diff_parse.h +18 -0
  118. data/vendor/libgit2/src/diff_print.c +263 -144
  119. data/vendor/libgit2/src/diff_stats.c +21 -12
  120. data/vendor/libgit2/src/diff_tform.c +1 -0
  121. data/vendor/libgit2/src/diff_tform.h +22 -0
  122. data/vendor/libgit2/src/diff_xdiff.c +9 -9
  123. data/vendor/libgit2/src/diff_xdiff.h +5 -5
  124. data/vendor/libgit2/src/fetchhead.c +8 -8
  125. data/vendor/libgit2/src/filebuf.c +6 -1
  126. data/vendor/libgit2/src/filebuf.h +1 -0
  127. data/vendor/libgit2/src/fileops.c +22 -1
  128. data/vendor/libgit2/src/fileops.h +8 -2
  129. data/vendor/libgit2/src/fnmatch.c +18 -5
  130. data/vendor/libgit2/src/global.c +21 -4
  131. data/vendor/libgit2/src/global.h +6 -0
  132. data/vendor/libgit2/src/graph.c +1 -1
  133. data/vendor/libgit2/src/index.c +159 -46
  134. data/vendor/libgit2/src/index.h +2 -0
  135. data/vendor/libgit2/src/iterator.c +1573 -1468
  136. data/vendor/libgit2/src/iterator.h +52 -69
  137. data/vendor/libgit2/src/merge.c +163 -64
  138. data/vendor/libgit2/src/merge.h +61 -2
  139. data/vendor/libgit2/src/merge_driver.c +397 -0
  140. data/vendor/libgit2/src/merge_driver.h +60 -0
  141. data/vendor/libgit2/src/merge_file.c +11 -49
  142. data/vendor/libgit2/src/netops.c +12 -10
  143. data/vendor/libgit2/src/object_api.c +19 -1
  144. data/vendor/libgit2/src/odb.c +228 -52
  145. data/vendor/libgit2/src/odb_loose.c +19 -1
  146. data/vendor/libgit2/src/odb_mempack.c +1 -1
  147. data/vendor/libgit2/src/odb_pack.c +27 -1
  148. data/vendor/libgit2/src/openssl_stream.c +4 -5
  149. data/vendor/libgit2/src/pack-objects.c +105 -76
  150. data/vendor/libgit2/src/pack-objects.h +13 -12
  151. data/vendor/libgit2/src/pack.c +16 -10
  152. data/vendor/libgit2/src/pack.h +2 -0
  153. data/vendor/libgit2/src/patch.c +216 -0
  154. data/vendor/libgit2/src/patch.h +66 -0
  155. data/vendor/libgit2/src/{diff_patch.c → patch_generate.c} +203 -376
  156. data/vendor/libgit2/src/patch_generate.h +68 -0
  157. data/vendor/libgit2/src/patch_parse.c +1159 -0
  158. data/vendor/libgit2/src/patch_parse.h +56 -0
  159. data/vendor/libgit2/src/path.c +38 -2
  160. data/vendor/libgit2/src/path.h +18 -0
  161. data/vendor/libgit2/src/pathspec.c +1 -1
  162. data/vendor/libgit2/src/pool.h +5 -0
  163. data/vendor/libgit2/src/pqueue.c +12 -5
  164. data/vendor/libgit2/src/pqueue.h +1 -0
  165. data/vendor/libgit2/src/proxy.c +32 -0
  166. data/vendor/libgit2/src/proxy.h +14 -0
  167. data/vendor/libgit2/src/push.c +1 -1
  168. data/vendor/libgit2/src/rebase.c +63 -36
  169. data/vendor/libgit2/src/refdb.c +4 -2
  170. data/vendor/libgit2/src/refdb_fs.c +82 -54
  171. data/vendor/libgit2/src/refs.c +13 -1
  172. data/vendor/libgit2/src/remote.c +20 -81
  173. data/vendor/libgit2/src/repository.c +212 -29
  174. data/vendor/libgit2/src/reset.c +1 -1
  175. data/vendor/libgit2/src/revparse.c +1 -1
  176. data/vendor/libgit2/src/revwalk.c +260 -184
  177. data/vendor/libgit2/src/settings.c +11 -3
  178. data/vendor/libgit2/src/signature.c +27 -2
  179. data/vendor/libgit2/src/sortedcache.c +14 -5
  180. data/vendor/libgit2/src/stash.c +1 -0
  181. data/vendor/libgit2/src/status.c +1 -0
  182. data/vendor/libgit2/src/stransport_stream.c +4 -2
  183. data/vendor/libgit2/src/stream.h +2 -2
  184. data/vendor/libgit2/src/submodule.c +16 -4
  185. data/vendor/libgit2/src/sysdir.c +1 -1
  186. data/vendor/libgit2/src/transport.c +3 -5
  187. data/vendor/libgit2/src/transports/http.c +38 -13
  188. data/vendor/libgit2/src/transports/local.c +4 -1
  189. data/vendor/libgit2/src/transports/smart.c +6 -0
  190. data/vendor/libgit2/src/transports/smart.h +1 -0
  191. data/vendor/libgit2/src/transports/smart_pkt.c +5 -13
  192. data/vendor/libgit2/src/transports/smart_protocol.c +22 -7
  193. data/vendor/libgit2/src/transports/winhttp.c +144 -11
  194. data/vendor/libgit2/src/tree.c +267 -2
  195. data/vendor/libgit2/src/unix/posix.h +10 -0
  196. data/vendor/libgit2/src/unix/pthread.h +2 -0
  197. data/vendor/libgit2/src/util.c +25 -2
  198. data/vendor/libgit2/src/util.h +10 -0
  199. data/vendor/libgit2/src/varint.c +44 -0
  200. data/vendor/libgit2/src/varint.h +15 -0
  201. data/vendor/libgit2/src/vector.c +58 -0
  202. data/vendor/libgit2/src/vector.h +8 -0
  203. data/vendor/libgit2/src/win32/posix.h +3 -0
  204. data/vendor/libgit2/src/win32/thread.c +18 -0
  205. data/vendor/libgit2/src/win32/thread.h +2 -0
  206. data/vendor/libgit2/src/win32/w32_util.h +1 -1
  207. data/vendor/libgit2/src/zstream.c +37 -8
  208. data/vendor/libgit2/src/zstream.h +8 -1
  209. metadata +100 -82
  210. data/vendor/libgit2/Makefile.embed +0 -60
  211. data/vendor/libgit2/src/delta-apply.c +0 -166
  212. data/vendor/libgit2/src/delta-apply.h +0 -62
  213. data/vendor/libgit2/src/diff_patch.h +0 -83
@@ -28,7 +28,7 @@ struct unpacked {
28
28
  git_pobject *object;
29
29
  void *data;
30
30
  struct git_delta_index *index;
31
- int depth;
31
+ size_t depth;
32
32
  };
33
33
 
34
34
  struct tree_walk_context {
@@ -99,8 +99,15 @@ static int packbuilder_config(git_packbuilder *pb)
99
99
 
100
100
  #define config_get(KEY,DST,DFLT) do { \
101
101
  ret = git_config_get_int64(&val, config, KEY); \
102
- if (!ret) (DST) = val; \
103
- else if (ret == GIT_ENOTFOUND) { \
102
+ if (!ret) { \
103
+ if (!git__is_sizet(val)) { \
104
+ giterr_set(GITERR_CONFIG, \
105
+ "configuration value '%s' is too large", KEY); \
106
+ ret = -1; \
107
+ goto out; \
108
+ } \
109
+ (DST) = (size_t)val; \
110
+ } else if (ret == GIT_ENOTFOUND) { \
104
111
  (DST) = (DFLT); \
105
112
  ret = 0; \
106
113
  } else if (ret < 0) goto out; } while (0)
@@ -144,7 +151,7 @@ int git_packbuilder_new(git_packbuilder **out, git_repository *repo)
144
151
  pb->nr_threads = 1; /* do not spawn any thread by default */
145
152
 
146
153
  if (git_hash_ctx_init(&pb->ctx) < 0 ||
147
- git_zstream_init(&pb->zstream) < 0 ||
154
+ git_zstream_init(&pb->zstream, GIT_ZSTREAM_DEFLATE) < 0 ||
148
155
  git_repository_odb(&pb->odb, repo) < 0 ||
149
156
  packbuilder_config(pb) < 0)
150
157
  goto on_error;
@@ -187,7 +194,7 @@ static void rehash(git_packbuilder *pb)
187
194
  {
188
195
  git_pobject *po;
189
196
  khiter_t pos;
190
- unsigned int i;
197
+ size_t i;
191
198
  int ret;
192
199
 
193
200
  kh_clear(oid, pb->object_ix);
@@ -222,7 +229,7 @@ int git_packbuilder_insert(git_packbuilder *pb, const git_oid *oid,
222
229
  return -1;
223
230
  }
224
231
 
225
- pb->nr_alloc = (uint32_t)newsize;
232
+ pb->nr_alloc = newsize;
226
233
 
227
234
  pb->object_list = git__reallocarray(pb->object_list,
228
235
  pb->nr_alloc, sizeof(*po));
@@ -272,8 +279,9 @@ int git_packbuilder_insert(git_packbuilder *pb, const git_oid *oid,
272
279
  static int get_delta(void **out, git_odb *odb, git_pobject *po)
273
280
  {
274
281
  git_odb_object *src = NULL, *trg = NULL;
275
- unsigned long delta_size;
282
+ size_t delta_size;
276
283
  void *delta_buf;
284
+ int error;
277
285
 
278
286
  *out = NULL;
279
287
 
@@ -281,12 +289,15 @@ static int get_delta(void **out, git_odb *odb, git_pobject *po)
281
289
  git_odb_read(&trg, odb, &po->id) < 0)
282
290
  goto on_error;
283
291
 
284
- delta_buf = git_delta(
285
- git_odb_object_data(src), (unsigned long)git_odb_object_size(src),
286
- git_odb_object_data(trg), (unsigned long)git_odb_object_size(trg),
287
- &delta_size, 0);
292
+ error = git_delta(&delta_buf, &delta_size,
293
+ git_odb_object_data(src), git_odb_object_size(src),
294
+ git_odb_object_data(trg), git_odb_object_size(trg),
295
+ 0);
288
296
 
289
- if (!delta_buf || delta_size != po->delta_size) {
297
+ if (error < 0 && error != GIT_EBUFS)
298
+ goto on_error;
299
+
300
+ if (error == GIT_EBUFS || delta_size != po->delta_size) {
290
301
  giterr_set(GITERR_INVALID, "Delta size changed");
291
302
  goto on_error;
292
303
  }
@@ -437,8 +448,8 @@ static int write_one(
437
448
  return write_object(pb, po, write_cb, cb_data);
438
449
  }
439
450
 
440
- GIT_INLINE(void) add_to_write_order(git_pobject **wo, unsigned int *endp,
441
- git_pobject *po)
451
+ GIT_INLINE(void) add_to_write_order(git_pobject **wo, size_t *endp,
452
+ git_pobject *po)
442
453
  {
443
454
  if (po->filled)
444
455
  return;
@@ -446,8 +457,8 @@ GIT_INLINE(void) add_to_write_order(git_pobject **wo, unsigned int *endp,
446
457
  po->filled = 1;
447
458
  }
448
459
 
449
- static void add_descendants_to_write_order(git_pobject **wo, unsigned int *endp,
450
- git_pobject *po)
460
+ static void add_descendants_to_write_order(git_pobject **wo, size_t *endp,
461
+ git_pobject *po)
451
462
  {
452
463
  int add_to_order = 1;
453
464
  while (po) {
@@ -488,8 +499,8 @@ static void add_descendants_to_write_order(git_pobject **wo, unsigned int *endp,
488
499
  };
489
500
  }
490
501
 
491
- static void add_family_to_write_order(git_pobject **wo, unsigned int *endp,
492
- git_pobject *po)
502
+ static void add_family_to_write_order(git_pobject **wo, size_t *endp,
503
+ git_pobject *po)
493
504
  {
494
505
  git_pobject *root;
495
506
 
@@ -520,7 +531,7 @@ static int cb_tag_foreach(const char *name, git_oid *oid, void *data)
520
531
 
521
532
  static git_pobject **compute_write_order(git_packbuilder *pb)
522
533
  {
523
- unsigned int i, wo_end, last_untagged;
534
+ size_t i, wo_end, last_untagged;
524
535
  git_pobject **wo;
525
536
 
526
537
  if ((wo = git__mallocarray(pb->nr_objects, sizeof(*wo))) == NULL)
@@ -625,13 +636,18 @@ static int write_pack(git_packbuilder *pb,
625
636
  enum write_one_status status;
626
637
  struct git_pack_header ph;
627
638
  git_oid entry_oid;
628
- unsigned int i = 0;
639
+ size_t i = 0;
629
640
  int error = 0;
630
641
 
631
642
  write_order = compute_write_order(pb);
632
643
  if (write_order == NULL)
633
644
  return -1;
634
645
 
646
+ if (!git__is_uint32(pb->nr_objects)) {
647
+ giterr_set(GITERR_INVALID, "too many objects");
648
+ return -1;
649
+ }
650
+
635
651
  /* Write pack header */
636
652
  ph.hdr_signature = htonl(PACK_SIGNATURE);
637
653
  ph.hdr_version = htonl(PACK_VERSION);
@@ -707,11 +723,18 @@ static int type_size_sort(const void *_a, const void *_b)
707
723
  return a < b ? -1 : (a > b); /* newest first */
708
724
  }
709
725
 
710
- static int delta_cacheable(git_packbuilder *pb, unsigned long src_size,
711
- unsigned long trg_size, unsigned long delta_size)
726
+ static int delta_cacheable(
727
+ git_packbuilder *pb,
728
+ size_t src_size,
729
+ size_t trg_size,
730
+ size_t delta_size)
712
731
  {
713
- if (pb->max_delta_cache_size &&
714
- pb->delta_cache_size + delta_size > pb->max_delta_cache_size)
732
+ size_t new_size;
733
+
734
+ if (git__add_sizet_overflow(&new_size, pb->delta_cache_size, delta_size))
735
+ return 0;
736
+
737
+ if (pb->max_delta_cache_size && new_size > pb->max_delta_cache_size)
715
738
  return 0;
716
739
 
717
740
  if (delta_size < pb->cache_max_small_delta_size)
@@ -725,15 +748,14 @@ static int delta_cacheable(git_packbuilder *pb, unsigned long src_size,
725
748
  }
726
749
 
727
750
  static int try_delta(git_packbuilder *pb, struct unpacked *trg,
728
- struct unpacked *src, int max_depth,
729
- unsigned long *mem_usage, int *ret)
751
+ struct unpacked *src, size_t max_depth,
752
+ size_t *mem_usage, int *ret)
730
753
  {
731
754
  git_pobject *trg_object = trg->object;
732
755
  git_pobject *src_object = src->object;
733
756
  git_odb_object *obj;
734
- unsigned long trg_size, src_size, delta_size,
735
- sizediff, max_size, sz;
736
- unsigned int ref_depth;
757
+ size_t trg_size, src_size, delta_size, sizediff, max_size, sz;
758
+ size_t ref_depth;
737
759
  void *delta_buf;
738
760
 
739
761
  /* Don't bother doing diffs between different types */
@@ -751,7 +773,7 @@ static int try_delta(git_packbuilder *pb, struct unpacked *trg,
751
773
  return 0;
752
774
 
753
775
  /* Now some size filtering heuristics. */
754
- trg_size = (unsigned long)trg_object->size;
776
+ trg_size = trg_object->size;
755
777
  if (!trg_object->delta) {
756
778
  max_size = trg_size/2 - 20;
757
779
  ref_depth = 1;
@@ -765,7 +787,7 @@ static int try_delta(git_packbuilder *pb, struct unpacked *trg,
765
787
  if (max_size == 0)
766
788
  return 0;
767
789
 
768
- src_size = (unsigned long)src_object->size;
790
+ src_size = src_object->size;
769
791
  sizediff = src_size < trg_size ? trg_size - src_size : 0;
770
792
  if (sizediff >= max_size)
771
793
  return 0;
@@ -777,7 +799,7 @@ static int try_delta(git_packbuilder *pb, struct unpacked *trg,
777
799
  if (git_odb_read(&obj, pb->odb, &trg_object->id) < 0)
778
800
  return -1;
779
801
 
780
- sz = (unsigned long)git_odb_object_size(obj);
802
+ sz = git_odb_object_size(obj);
781
803
  trg->data = git__malloc(sz);
782
804
  GITERR_CHECK_ALLOC(trg->data);
783
805
  memcpy(trg->data, git_odb_object_data(obj), sz);
@@ -799,7 +821,7 @@ static int try_delta(git_packbuilder *pb, struct unpacked *trg,
799
821
  !git__is_ulong(obj_sz = git_odb_object_size(obj)))
800
822
  return -1;
801
823
 
802
- sz = (unsigned long)obj_sz;
824
+ sz = obj_sz;
803
825
  src->data = git__malloc(sz);
804
826
  GITERR_CHECK_ALLOC(src->data);
805
827
  memcpy(src->data, git_odb_object_data(obj), sz);
@@ -815,16 +837,14 @@ static int try_delta(git_packbuilder *pb, struct unpacked *trg,
815
837
  *mem_usage += sz;
816
838
  }
817
839
  if (!src->index) {
818
- src->index = git_delta_create_index(src->data, src_size);
819
- if (!src->index)
840
+ if (git_delta_index_init(&src->index, src->data, src_size) < 0)
820
841
  return 0; /* suboptimal pack - out of memory */
821
842
 
822
- *mem_usage += git_delta_sizeof_index(src->index);
843
+ *mem_usage += git_delta_index_size(src->index);
823
844
  }
824
845
 
825
- delta_buf = git_delta_create(src->index, trg->data, trg_size,
826
- &delta_size, max_size);
827
- if (!delta_buf)
846
+ if (git_delta_create_from_index(&delta_buf, &delta_size, src->index, trg->data, trg_size,
847
+ max_size) < 0)
828
848
  return 0;
829
849
 
830
850
  if (trg_object->delta) {
@@ -839,11 +859,12 @@ static int try_delta(git_packbuilder *pb, struct unpacked *trg,
839
859
  git_packbuilder__cache_lock(pb);
840
860
  if (trg_object->delta_data) {
841
861
  git__free(trg_object->delta_data);
862
+ assert(pb->delta_cache_size >= trg_object->delta_size);
842
863
  pb->delta_cache_size -= trg_object->delta_size;
843
864
  trg_object->delta_data = NULL;
844
865
  }
845
866
  if (delta_cacheable(pb, src_size, trg_size, delta_size)) {
846
- bool overflow = git__add_uint64_overflow(
867
+ bool overflow = git__add_sizet_overflow(
847
868
  &pb->delta_cache_size, pb->delta_cache_size, delta_size);
848
869
 
849
870
  git_packbuilder__cache_unlock(pb);
@@ -869,13 +890,13 @@ static int try_delta(git_packbuilder *pb, struct unpacked *trg,
869
890
  return 0;
870
891
  }
871
892
 
872
- static unsigned int check_delta_limit(git_pobject *me, unsigned int n)
893
+ static size_t check_delta_limit(git_pobject *me, size_t n)
873
894
  {
874
895
  git_pobject *child = me->delta_child;
875
- unsigned int m = n;
896
+ size_t m = n;
876
897
 
877
898
  while (child) {
878
- unsigned int c = check_delta_limit(child, n + 1);
899
+ size_t c = check_delta_limit(child, n + 1);
879
900
  if (m < c)
880
901
  m = c;
881
902
  child = child->delta_sibling;
@@ -883,13 +904,18 @@ static unsigned int check_delta_limit(git_pobject *me, unsigned int n)
883
904
  return m;
884
905
  }
885
906
 
886
- static unsigned long free_unpacked(struct unpacked *n)
907
+ static size_t free_unpacked(struct unpacked *n)
887
908
  {
888
- unsigned long freed_mem = git_delta_sizeof_index(n->index);
889
- git_delta_free_index(n->index);
909
+ size_t freed_mem = 0;
910
+
911
+ if (n->index) {
912
+ freed_mem += git_delta_index_size(n->index);
913
+ git_delta_index_free(n->index);
914
+ }
890
915
  n->index = NULL;
916
+
891
917
  if (n->data) {
892
- freed_mem += (unsigned long)n->object->size;
918
+ freed_mem += n->object->size;
893
919
  git__free(n->data);
894
920
  n->data = NULL;
895
921
  }
@@ -898,7 +924,8 @@ static unsigned long free_unpacked(struct unpacked *n)
898
924
  return freed_mem;
899
925
  }
900
926
 
901
- static int report_delta_progress(git_packbuilder *pb, uint32_t count, bool force)
927
+ static int report_delta_progress(
928
+ git_packbuilder *pb, uint32_t count, bool force)
902
929
  {
903
930
  int ret;
904
931
 
@@ -922,15 +949,14 @@ static int report_delta_progress(git_packbuilder *pb, uint32_t count, bool force
922
949
  }
923
950
 
924
951
  static int find_deltas(git_packbuilder *pb, git_pobject **list,
925
- unsigned int *list_size, unsigned int window,
926
- int depth)
952
+ size_t *list_size, size_t window, size_t depth)
927
953
  {
928
954
  git_pobject *po;
929
955
  git_buf zbuf = GIT_BUF_INIT;
930
956
  struct unpacked *array;
931
- uint32_t idx = 0, count = 0;
932
- unsigned long mem_usage = 0;
933
- unsigned int i;
957
+ size_t idx = 0, count = 0;
958
+ size_t mem_usage = 0;
959
+ size_t i;
934
960
  int error = -1;
935
961
 
936
962
  array = git__calloc(window, sizeof(struct unpacked));
@@ -938,7 +964,7 @@ static int find_deltas(git_packbuilder *pb, git_pobject **list,
938
964
 
939
965
  for (;;) {
940
966
  struct unpacked *n = array + idx;
941
- int max_depth, j, best_base = -1;
967
+ size_t max_depth, j, best_base = SIZE_MAX;
942
968
 
943
969
  git_packbuilder__progress_lock(pb);
944
970
  if (!*list_size) {
@@ -959,7 +985,7 @@ static int find_deltas(git_packbuilder *pb, git_pobject **list,
959
985
  while (pb->window_memory_limit &&
960
986
  mem_usage > pb->window_memory_limit &&
961
987
  count > 1) {
962
- uint32_t tail = (idx + window - count) % window;
988
+ size_t tail = (idx + window - count) % window;
963
989
  mem_usage -= free_unpacked(array + tail);
964
990
  count--;
965
991
  }
@@ -971,15 +997,18 @@ static int find_deltas(git_packbuilder *pb, git_pobject **list,
971
997
  */
972
998
  max_depth = depth;
973
999
  if (po->delta_child) {
974
- max_depth -= check_delta_limit(po, 0);
975
- if (max_depth <= 0)
1000
+ size_t delta_limit = check_delta_limit(po, 0);
1001
+
1002
+ if (delta_limit > max_depth)
976
1003
  goto next;
1004
+
1005
+ max_depth -= delta_limit;
977
1006
  }
978
1007
 
979
1008
  j = window;
980
1009
  while (--j > 0) {
981
1010
  int ret;
982
- uint32_t other_idx = idx + j;
1011
+ size_t other_idx = idx + j;
983
1012
  struct unpacked *m;
984
1013
 
985
1014
  if (other_idx >= window)
@@ -1020,7 +1049,7 @@ static int find_deltas(git_packbuilder *pb, git_pobject **list,
1020
1049
  GITERR_CHECK_ALLOC(po->delta_data);
1021
1050
 
1022
1051
  memcpy(po->delta_data, zbuf.ptr, zbuf.size);
1023
- po->z_delta_size = (unsigned long)zbuf.size;
1052
+ po->z_delta_size = zbuf.size;
1024
1053
  git_buf_clear(&zbuf);
1025
1054
 
1026
1055
  git_packbuilder__cache_lock(pb);
@@ -1044,10 +1073,10 @@ static int find_deltas(git_packbuilder *pb, git_pobject **list,
1044
1073
  */
1045
1074
  if (po->delta) {
1046
1075
  struct unpacked swap = array[best_base];
1047
- int dist = (window + idx - best_base) % window;
1048
- int dst = best_base;
1076
+ size_t dist = (window + idx - best_base) % window;
1077
+ size_t dst = best_base;
1049
1078
  while (dist--) {
1050
- int src = (dst + 1) % window;
1079
+ size_t src = (dst + 1) % window;
1051
1080
  array[dst] = array[src];
1052
1081
  dst = src;
1053
1082
  }
@@ -1085,13 +1114,13 @@ struct thread_params {
1085
1114
  git_cond cond;
1086
1115
  git_mutex mutex;
1087
1116
 
1088
- unsigned int list_size;
1089
- unsigned int remaining;
1117
+ size_t list_size;
1118
+ size_t remaining;
1090
1119
 
1091
- int window;
1092
- int depth;
1093
- int working;
1094
- int data_ready;
1120
+ size_t window;
1121
+ size_t depth;
1122
+ size_t working;
1123
+ size_t data_ready;
1095
1124
  };
1096
1125
 
1097
1126
  static void *threaded_find_deltas(void *arg)
@@ -1133,11 +1162,11 @@ static void *threaded_find_deltas(void *arg)
1133
1162
  }
1134
1163
 
1135
1164
  static int ll_find_deltas(git_packbuilder *pb, git_pobject **list,
1136
- unsigned int list_size, unsigned int window,
1137
- int depth)
1165
+ size_t list_size, size_t window, size_t depth)
1138
1166
  {
1139
1167
  struct thread_params *p;
1140
- int i, ret, active_threads = 0;
1168
+ size_t i;
1169
+ int ret, active_threads = 0;
1141
1170
 
1142
1171
  if (!pb->nr_threads)
1143
1172
  pb->nr_threads = git_online_cpus();
@@ -1152,7 +1181,7 @@ static int ll_find_deltas(git_packbuilder *pb, git_pobject **list,
1152
1181
 
1153
1182
  /* Partition the work among the threads */
1154
1183
  for (i = 0; i < pb->nr_threads; ++i) {
1155
- unsigned sub_size = list_size / (pb->nr_threads - i);
1184
+ size_t sub_size = list_size / (pb->nr_threads - i);
1156
1185
 
1157
1186
  /* don't use too small segments or no deltas will be found */
1158
1187
  if (sub_size < 2*window && i+1 < pb->nr_threads)
@@ -1206,7 +1235,7 @@ static int ll_find_deltas(git_packbuilder *pb, git_pobject **list,
1206
1235
  while (active_threads) {
1207
1236
  struct thread_params *target = NULL;
1208
1237
  struct thread_params *victim = NULL;
1209
- unsigned sub_size = 0;
1238
+ size_t sub_size = 0;
1210
1239
 
1211
1240
  /* Start by locating a thread that has transitioned its
1212
1241
  * 'working' flag from 1 -> 0. This indicates that it is
@@ -1286,7 +1315,7 @@ static int ll_find_deltas(git_packbuilder *pb, git_pobject **list,
1286
1315
  static int prepare_pack(git_packbuilder *pb)
1287
1316
  {
1288
1317
  git_pobject **delta_list;
1289
- unsigned int i, n = 0;
1318
+ size_t i, n = 0;
1290
1319
 
1291
1320
  if (pb->nr_objects == 0 || pb->done)
1292
1321
  return 0; /* nothing to do */
@@ -1473,12 +1502,12 @@ cleanup:
1473
1502
  return error;
1474
1503
  }
1475
1504
 
1476
- uint32_t git_packbuilder_object_count(git_packbuilder *pb)
1505
+ size_t git_packbuilder_object_count(git_packbuilder *pb)
1477
1506
  {
1478
1507
  return pb->nr_objects;
1479
1508
  }
1480
1509
 
1481
- uint32_t git_packbuilder_written(git_packbuilder *pb)
1510
+ size_t git_packbuilder_written(git_packbuilder *pb)
1482
1511
  {
1483
1512
  return pb->nr_written;
1484
1513
  }
@@ -42,8 +42,8 @@ typedef struct git_pobject {
42
42
  * me */
43
43
 
44
44
  void *delta_data;
45
- unsigned long delta_size;
46
- unsigned long z_delta_size;
45
+ size_t delta_size;
46
+ size_t z_delta_size;
47
47
 
48
48
  int written:1,
49
49
  recursing:1,
@@ -65,10 +65,11 @@ struct git_packbuilder {
65
65
  git_zstream zstream;
66
66
 
67
67
  uint32_t nr_objects,
68
- nr_deltified,
69
- nr_alloc,
70
- nr_written,
71
- nr_remaining;
68
+ nr_deltified,
69
+ nr_written,
70
+ nr_remaining;
71
+
72
+ size_t nr_alloc;
72
73
 
73
74
  git_pobject *object_list;
74
75
 
@@ -85,13 +86,13 @@ struct git_packbuilder {
85
86
  git_cond progress_cond;
86
87
 
87
88
  /* configs */
88
- uint64_t delta_cache_size;
89
- uint64_t max_delta_cache_size;
90
- uint64_t cache_max_small_delta_size;
91
- uint64_t big_file_threshold;
92
- uint64_t window_memory_limit;
89
+ size_t delta_cache_size;
90
+ size_t max_delta_cache_size;
91
+ size_t cache_max_small_delta_size;
92
+ size_t big_file_threshold;
93
+ size_t window_memory_limit;
93
94
 
94
- int nr_threads; /* nr of threads to use */
95
+ unsigned int nr_threads; /* nr of threads to use */
95
96
 
96
97
  git_packbuilder_progress progress_cb;
97
98
  void *progress_cb_payload;
@@ -8,7 +8,7 @@
8
8
  #include "common.h"
9
9
  #include "odb.h"
10
10
  #include "pack.h"
11
- #include "delta-apply.h"
11
+ #include "delta.h"
12
12
  #include "sha1_lookup.h"
13
13
  #include "mwindow.h"
14
14
  #include "fileops.h"
@@ -505,12 +505,14 @@ int git_packfile_resolve_header(
505
505
  git_mwindow_close(&w_curs);
506
506
  if ((error = git_packfile_stream_open(&stream, p, curpos)) < 0)
507
507
  return error;
508
- error = git__delta_read_header_fromstream(&base_size, size_p, &stream);
508
+ error = git_delta_read_header_fromstream(&base_size, size_p, &stream);
509
509
  git_packfile_stream_free(&stream);
510
510
  if (error < 0)
511
511
  return error;
512
- } else
512
+ } else {
513
513
  *size_p = size;
514
+ base_offset = 0;
515
+ }
514
516
 
515
517
  while (type == GIT_OBJ_OFS_DELTA || type == GIT_OBJ_REF_DELTA) {
516
518
  curpos = base_offset;
@@ -730,8 +732,9 @@ int git_packfile_unpack(
730
732
  obj->len = 0;
731
733
  obj->type = GIT_OBJ_BAD;
732
734
 
733
- error = git__delta_apply(obj, base.data, base.len, delta.data, delta.len);
735
+ error = git_delta_apply(&obj->data, &obj->len, base.data, base.len, delta.data, delta.len);
734
736
  obj->type = base_type;
737
+
735
738
  /*
736
739
  * We usually don't want to free the base at this
737
740
  * point, as we put it into the cache in the previous
@@ -756,8 +759,11 @@ int git_packfile_unpack(
756
759
  }
757
760
 
758
761
  cleanup:
759
- if (error < 0)
762
+ if (error < 0) {
760
763
  git__free(obj->data);
764
+ if (cached)
765
+ git_atomic_dec(&cached->refcount);
766
+ }
761
767
 
762
768
  if (elem)
763
769
  *obj_offset = curpos;
@@ -1267,8 +1273,8 @@ static int pack_entry_find_offset(
1267
1273
  const git_oid *short_oid,
1268
1274
  size_t len)
1269
1275
  {
1270
- const uint32_t *level1_ofs = p->index_map.data;
1271
- const unsigned char *index = p->index_map.data;
1276
+ const uint32_t *level1_ofs;
1277
+ const unsigned char *index;
1272
1278
  unsigned hi, lo, stride;
1273
1279
  int pos, found = 0;
1274
1280
  git_off_t offset;
@@ -1282,11 +1288,11 @@ static int pack_entry_find_offset(
1282
1288
  if ((error = pack_index_open(p)) < 0)
1283
1289
  return error;
1284
1290
  assert(p->index_map.data);
1285
-
1286
- index = p->index_map.data;
1287
- level1_ofs = p->index_map.data;
1288
1291
  }
1289
1292
 
1293
+ index = p->index_map.data;
1294
+ level1_ofs = p->index_map.data;
1295
+
1290
1296
  if (p->index_version > 1) {
1291
1297
  level1_ofs += 2;
1292
1298
  index += 8;
@@ -102,6 +102,8 @@ struct git_pack_file {
102
102
 
103
103
  git_pack_cache bases; /* delta base cache */
104
104
 
105
+ time_t last_freshen; /* last time the packfile was freshened */
106
+
105
107
  /* something like ".git/objects/pack/xxxxx.pack" */
106
108
  char pack_name[GIT_FLEX_ARRAY]; /* more */
107
109
  };