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
@@ -12,12 +12,13 @@
12
12
  #include "fileops.h"
13
13
  #include "hash.h"
14
14
  #include "odb.h"
15
- #include "delta-apply.h"
15
+ #include "delta.h"
16
16
  #include "filter.h"
17
17
  #include "repository.h"
18
18
 
19
19
  #include "git2/odb_backend.h"
20
20
  #include "git2/oid.h"
21
+ #include "git2/oidarray.h"
21
22
 
22
23
  #define GIT_ALTERNATES_FILE "info/alternates"
23
24
 
@@ -48,8 +49,32 @@ static git_cache *odb_cache(git_odb *odb)
48
49
  return &odb->own_cache;
49
50
  }
50
51
 
52
+ static int odb_otype_fast(git_otype *type_p, git_odb *db, const git_oid *id);
51
53
  static int load_alternates(git_odb *odb, const char *objects_dir, int alternate_depth);
52
54
 
55
+ static git_otype odb_hardcoded_type(const git_oid *id)
56
+ {
57
+ static git_oid empty_tree = {{ 0x4b, 0x82, 0x5d, 0xc6, 0x42, 0xcb, 0x6e, 0xb9, 0xa0, 0x60,
58
+ 0xe5, 0x4b, 0xf8, 0xd6, 0x92, 0x88, 0xfb, 0xee, 0x49, 0x04 }};
59
+
60
+ if (!git_oid_cmp(id, &empty_tree))
61
+ return GIT_OBJ_TREE;
62
+
63
+ return GIT_OBJ_BAD;
64
+ }
65
+
66
+ static int odb_read_hardcoded(git_rawobj *raw, const git_oid *id)
67
+ {
68
+ git_otype type = odb_hardcoded_type(id);
69
+ if (type == GIT_OBJ_BAD)
70
+ return -1;
71
+
72
+ raw->type = type;
73
+ raw->len = 0;
74
+ raw->data = git__calloc(1, sizeof(uint8_t));
75
+ return 0;
76
+ }
77
+
53
78
  int git_odb__format_object_header(char *hdr, size_t n, git_off_t obj_len, git_otype obj_type)
54
79
  {
55
80
  const char *type_str = git_object_type2string(obj_type);
@@ -624,7 +649,10 @@ void git_odb_free(git_odb *db)
624
649
  GIT_REFCOUNT_DEC(db, odb_free);
625
650
  }
626
651
 
627
- static int odb_exists_1(git_odb *db, const git_oid *id, bool only_refreshed)
652
+ static int odb_exists_1(
653
+ git_odb *db,
654
+ const git_oid *id,
655
+ bool only_refreshed)
628
656
  {
629
657
  size_t i;
630
658
  bool found = false;
@@ -643,6 +671,44 @@ static int odb_exists_1(git_odb *db, const git_oid *id, bool only_refreshed)
643
671
  return (int)found;
644
672
  }
645
673
 
674
+ static int odb_freshen_1(
675
+ git_odb *db,
676
+ const git_oid *id,
677
+ bool only_refreshed)
678
+ {
679
+ size_t i;
680
+ bool found = false;
681
+
682
+ for (i = 0; i < db->backends.length && !found; ++i) {
683
+ backend_internal *internal = git_vector_get(&db->backends, i);
684
+ git_odb_backend *b = internal->backend;
685
+
686
+ if (only_refreshed && !b->refresh)
687
+ continue;
688
+
689
+ if (b->freshen != NULL)
690
+ found = !b->freshen(b, id);
691
+ else if (b->exists != NULL)
692
+ found = b->exists(b, id);
693
+ }
694
+
695
+ return (int)found;
696
+ }
697
+
698
+ static int odb_freshen(git_odb *db, const git_oid *id)
699
+ {
700
+ assert(db && id);
701
+
702
+ if (odb_freshen_1(db, id, false))
703
+ return 1;
704
+
705
+ if (!git_odb_refresh(db))
706
+ return odb_freshen_1(db, id, true);
707
+
708
+ /* Failed to refresh, hence not found */
709
+ return 0;
710
+ }
711
+
646
712
  int git_odb_exists(git_odb *db, const git_oid *id)
647
713
  {
648
714
  git_odb_object *object;
@@ -651,7 +717,7 @@ int git_odb_exists(git_odb *db, const git_oid *id)
651
717
 
652
718
  if ((object = git_cache_get_raw(odb_cache(db), id)) != NULL) {
653
719
  git_odb_object_free(object);
654
- return (int)true;
720
+ return 1;
655
721
  }
656
722
 
657
723
  if (odb_exists_1(db, id, false))
@@ -716,10 +782,8 @@ int git_odb_exists_prefix(
716
782
 
717
783
  if (len < GIT_OID_MINPREFIXLEN)
718
784
  return git_odb__error_ambiguous("prefix length too short");
719
- if (len > GIT_OID_HEXSZ)
720
- len = GIT_OID_HEXSZ;
721
785
 
722
- if (len == GIT_OID_HEXSZ) {
786
+ if (len >= GIT_OID_HEXSZ) {
723
787
  if (git_odb_exists(db, short_id)) {
724
788
  if (out)
725
789
  git_oid_cpy(out, short_id);
@@ -730,10 +794,7 @@ int git_odb_exists_prefix(
730
794
  }
731
795
  }
732
796
 
733
- /* just copy valid part of short_id */
734
- memcpy(&key.id, short_id->id, (len + 1) / 2);
735
- if (len & 1)
736
- key.id[len / 2] &= 0xF0;
797
+ git_oid__cpy_prefix(&key, short_id, len);
737
798
 
738
799
  error = odb_exists_prefix_1(out, db, &key, len, false);
739
800
 
@@ -746,6 +807,72 @@ int git_odb_exists_prefix(
746
807
  return error;
747
808
  }
748
809
 
810
+ int git_odb_expand_ids(
811
+ git_odb *db,
812
+ git_odb_expand_id *ids,
813
+ size_t count)
814
+ {
815
+ size_t i;
816
+
817
+ assert(db && ids);
818
+
819
+ for (i = 0; i < count; i++) {
820
+ git_odb_expand_id *query = &ids[i];
821
+ int error = GIT_EAMBIGUOUS;
822
+
823
+ if (!query->type)
824
+ query->type = GIT_OBJ_ANY;
825
+
826
+ /* if we have a short OID, expand it first */
827
+ if (query->length >= GIT_OID_MINPREFIXLEN && query->length < GIT_OID_HEXSZ) {
828
+ git_oid actual_id;
829
+
830
+ error = odb_exists_prefix_1(&actual_id, db, &query->id, query->length, false);
831
+ if (!error) {
832
+ git_oid_cpy(&query->id, &actual_id);
833
+ query->length = GIT_OID_HEXSZ;
834
+ }
835
+ }
836
+
837
+ /*
838
+ * now we ought to have a 40-char OID, either because we've expanded it
839
+ * or because the user passed a full OID. Ensure its type is right.
840
+ */
841
+ if (query->length >= GIT_OID_HEXSZ) {
842
+ git_otype actual_type;
843
+
844
+ error = odb_otype_fast(&actual_type, db, &query->id);
845
+ if (!error) {
846
+ if (query->type != GIT_OBJ_ANY && query->type != actual_type)
847
+ error = GIT_ENOTFOUND;
848
+ else
849
+ query->type = actual_type;
850
+ }
851
+ }
852
+
853
+ switch (error) {
854
+ /* no errors, so we've successfully expanded the OID */
855
+ case 0:
856
+ continue;
857
+
858
+ /* the object is missing or ambiguous */
859
+ case GIT_ENOTFOUND:
860
+ case GIT_EAMBIGUOUS:
861
+ memset(&query->id, 0, sizeof(git_oid));
862
+ query->length = 0;
863
+ query->type = 0;
864
+ break;
865
+
866
+ /* something went very wrong with the ODB; bail hard */
867
+ default:
868
+ return error;
869
+ }
870
+ }
871
+
872
+ giterr_clear();
873
+ return 0;
874
+ }
875
+
749
876
  int git_odb_read_header(size_t *len_p, git_otype *type_p, git_odb *db, const git_oid *id)
750
877
  {
751
878
  int error;
@@ -759,11 +886,53 @@ int git_odb_read_header(size_t *len_p, git_otype *type_p, git_odb *db, const git
759
886
  return error;
760
887
  }
761
888
 
889
+ static int odb_read_header_1(
890
+ size_t *len_p, git_otype *type_p, git_odb *db,
891
+ const git_oid *id, bool only_refreshed)
892
+ {
893
+ size_t i;
894
+ git_otype ht;
895
+ bool passthrough = false;
896
+ int error;
897
+
898
+ if (!only_refreshed && (ht = odb_hardcoded_type(id)) != GIT_OBJ_BAD) {
899
+ *type_p = ht;
900
+ *len_p = 0;
901
+ return 0;
902
+ }
903
+
904
+ for (i = 0; i < db->backends.length; ++i) {
905
+ backend_internal *internal = git_vector_get(&db->backends, i);
906
+ git_odb_backend *b = internal->backend;
907
+
908
+ if (only_refreshed && !b->refresh)
909
+ continue;
910
+
911
+ if (!b->read_header) {
912
+ passthrough = true;
913
+ continue;
914
+ }
915
+
916
+ error = b->read_header(len_p, type_p, b, id);
917
+
918
+ switch (error) {
919
+ case GIT_PASSTHROUGH:
920
+ passthrough = true;
921
+ break;
922
+ case GIT_ENOTFOUND:
923
+ break;
924
+ default:
925
+ return error;
926
+ }
927
+ }
928
+
929
+ return passthrough ? GIT_PASSTHROUGH : GIT_ENOTFOUND;
930
+ }
931
+
762
932
  int git_odb__read_header_or_object(
763
933
  git_odb_object **out, size_t *len_p, git_otype *type_p,
764
934
  git_odb *db, const git_oid *id)
765
935
  {
766
- size_t i;
767
936
  int error = GIT_ENOTFOUND;
768
937
  git_odb_object *object;
769
938
 
@@ -777,45 +946,32 @@ int git_odb__read_header_or_object(
777
946
  }
778
947
 
779
948
  *out = NULL;
949
+ error = odb_read_header_1(len_p, type_p, db, id, false);
780
950
 
781
- for (i = 0; i < db->backends.length && error < 0; ++i) {
782
- backend_internal *internal = git_vector_get(&db->backends, i);
783
- git_odb_backend *b = internal->backend;
951
+ if (error == GIT_ENOTFOUND && !git_odb_refresh(db))
952
+ error = odb_read_header_1(len_p, type_p, db, id, true);
784
953
 
785
- if (b->read_header != NULL)
786
- error = b->read_header(len_p, type_p, b, id);
787
- }
954
+ if (error == GIT_ENOTFOUND)
955
+ return git_odb__error_notfound("cannot read header for", id, GIT_OID_HEXSZ);
788
956
 
789
- if (!error || error == GIT_PASSTHROUGH)
957
+ /* we found the header; return early */
958
+ if (!error)
790
959
  return 0;
791
960
 
792
- /*
793
- * no backend could read only the header.
794
- * try reading the whole object and freeing the contents
795
- */
796
- if ((error = git_odb_read(&object, db, id)) < 0)
797
- return error; /* error already set - pass along */
798
-
799
- *len_p = object->cached.size;
800
- *type_p = object->cached.type;
801
- *out = object;
802
-
803
- return 0;
804
- }
805
-
806
- static git_oid empty_tree = {{ 0x4b, 0x82, 0x5d, 0xc6, 0x42, 0xcb, 0x6e, 0xb9, 0xa0, 0x60,
807
- 0xe5, 0x4b, 0xf8, 0xd6, 0x92, 0x88, 0xfb, 0xee, 0x49, 0x04 }};
808
-
809
- static int hardcoded_objects(git_rawobj *raw, const git_oid *id)
810
- {
811
- if (!git_oid_cmp(id, &empty_tree)) {
812
- raw->type = GIT_OBJ_TREE;
813
- raw->len = 0;
814
- raw->data = git__calloc(1, sizeof(uint8_t));
815
- return 0;
816
- } else {
817
- return GIT_ENOTFOUND;
961
+ if (error == GIT_PASSTHROUGH) {
962
+ /*
963
+ * no backend has header-reading functionality
964
+ * so try using `git_odb_read` instead
965
+ */
966
+ error = git_odb_read(&object, db, id);
967
+ if (!error) {
968
+ *len_p = object->cached.size;
969
+ *type_p = object->cached.type;
970
+ *out = object;
971
+ }
818
972
  }
973
+
974
+ return error;
819
975
  }
820
976
 
821
977
  static int odb_read_1(git_odb_object **out, git_odb *db, const git_oid *id,
@@ -826,7 +982,7 @@ static int odb_read_1(git_odb_object **out, git_odb *db, const git_oid *id,
826
982
  git_odb_object *object;
827
983
  bool found = false;
828
984
 
829
- if (!hardcoded_objects(&raw, id))
985
+ if (!only_refreshed && odb_read_hardcoded(&raw, id) == 0)
830
986
  found = true;
831
987
 
832
988
  for (i = 0; i < db->backends.length && !found; ++i) {
@@ -880,6 +1036,29 @@ int git_odb_read(git_odb_object **out, git_odb *db, const git_oid *id)
880
1036
  return error;
881
1037
  }
882
1038
 
1039
+ static int odb_otype_fast(git_otype *type_p, git_odb *db, const git_oid *id)
1040
+ {
1041
+ git_odb_object *object;
1042
+ size_t _unused;
1043
+ int error;
1044
+
1045
+ if ((object = git_cache_get_raw(odb_cache(db), id)) != NULL) {
1046
+ *type_p = object->cached.type;
1047
+ return 0;
1048
+ }
1049
+
1050
+ error = odb_read_header_1(&_unused, type_p, db, id, false);
1051
+
1052
+ if (error == GIT_PASSTHROUGH) {
1053
+ error = odb_read_1(&object, db, id, false);
1054
+ if (!error)
1055
+ *type_p = object->cached.type;
1056
+ git_odb_object_free(object);
1057
+ }
1058
+
1059
+ return error;
1060
+ }
1061
+
883
1062
  static int read_prefix_1(git_odb_object **out, git_odb *db,
884
1063
  const git_oid *key, size_t len, bool only_refreshed)
885
1064
  {
@@ -950,10 +1129,7 @@ int git_odb_read_prefix(
950
1129
  return 0;
951
1130
  }
952
1131
 
953
- /* just copy valid part of short_id */
954
- memcpy(&key.id, short_id->id, (len + 1) / 2);
955
- if (len & 1)
956
- key.id[len / 2] &= 0xF0;
1132
+ git_oid__cpy_prefix(&key, short_id, len);
957
1133
 
958
1134
  error = read_prefix_1(out, db, &key, len, false);
959
1135
 
@@ -991,7 +1167,7 @@ int git_odb_write(
991
1167
  assert(oid && db);
992
1168
 
993
1169
  git_odb_hash(oid, data, len, type);
994
- if (git_odb_exists(db, oid))
1170
+ if (odb_freshen(db, oid))
995
1171
  return 0;
996
1172
 
997
1173
  for (i = 0; i < db->backends.length && error < 0; ++i) {
@@ -1117,7 +1293,7 @@ int git_odb_stream_finalize_write(git_oid *out, git_odb_stream *stream)
1117
1293
 
1118
1294
  git_hash_final(out, stream->hash_ctx);
1119
1295
 
1120
- if (git_odb_exists(stream->backend->odb, out))
1296
+ if (odb_freshen(stream->backend->odb, out))
1121
1297
  return 0;
1122
1298
 
1123
1299
  return stream->finalize_write(stream, out);
@@ -1224,7 +1400,7 @@ int git_odb__error_notfound(
1224
1400
  char oid_str[GIT_OID_HEXSZ + 1];
1225
1401
  git_oid_tostr(oid_str, oid_len+1, oid);
1226
1402
  giterr_set(GITERR_ODB, "Object not found - %s (%.*s)",
1227
- message, oid_len, oid_str);
1403
+ message, (int) oid_len, oid_str);
1228
1404
  } else
1229
1405
  giterr_set(GITERR_ODB, "Object not found - %s", message);
1230
1406
 
@@ -12,7 +12,7 @@
12
12
  #include "fileops.h"
13
13
  #include "hash.h"
14
14
  #include "odb.h"
15
- #include "delta-apply.h"
15
+ #include "delta.h"
16
16
  #include "filebuf.h"
17
17
 
18
18
  #include "git2/odb_backend.h"
@@ -918,6 +918,23 @@ cleanup:
918
918
  return error;
919
919
  }
920
920
 
921
+ static int loose_backend__freshen(
922
+ git_odb_backend *_backend,
923
+ const git_oid *oid)
924
+ {
925
+ loose_backend *backend = (loose_backend *)_backend;
926
+ git_buf path = GIT_BUF_INIT;
927
+ int error;
928
+
929
+ if (object_file_name(&path, backend, oid) < 0)
930
+ return -1;
931
+
932
+ error = git_futils_touch(path.ptr, NULL);
933
+ git_buf_free(&path);
934
+
935
+ return error;
936
+ }
937
+
921
938
  static void loose_backend__free(git_odb_backend *_backend)
922
939
  {
923
940
  loose_backend *backend;
@@ -975,6 +992,7 @@ int git_odb_backend_loose(
975
992
  backend->parent.exists = &loose_backend__exists;
976
993
  backend->parent.exists_prefix = &loose_backend__exists_prefix;
977
994
  backend->parent.foreach = &loose_backend__foreach;
995
+ backend->parent.freshen = &loose_backend__freshen;
978
996
  backend->parent.free = &loose_backend__free;
979
997
 
980
998
  *backend_out = (git_odb_backend *)backend;
@@ -24,7 +24,7 @@ struct memobject {
24
24
  git_oid oid;
25
25
  size_t len;
26
26
  git_otype type;
27
- char data[];
27
+ char data[GIT_FLEX_ARRAY];
28
28
  };
29
29
 
30
30
  struct memory_packer_db {
@@ -13,13 +13,16 @@
13
13
  #include "fileops.h"
14
14
  #include "hash.h"
15
15
  #include "odb.h"
16
- #include "delta-apply.h"
16
+ #include "delta.h"
17
17
  #include "sha1_lookup.h"
18
18
  #include "mwindow.h"
19
19
  #include "pack.h"
20
20
 
21
21
  #include "git2/odb_backend.h"
22
22
 
23
+ /* re-freshen pack files no more than every 2 seconds */
24
+ #define FRESHEN_FREQUENCY 2
25
+
23
26
  struct pack_backend {
24
27
  git_odb_backend parent;
25
28
  git_vector packs;
@@ -363,6 +366,28 @@ static int pack_backend__read_header(
363
366
  return git_packfile_resolve_header(len_p, type_p, e.p, e.offset);
364
367
  }
365
368
 
369
+ static int pack_backend__freshen(
370
+ git_odb_backend *backend, const git_oid *oid)
371
+ {
372
+ struct git_pack_entry e;
373
+ time_t now;
374
+ int error;
375
+
376
+ if ((error = pack_entry_find(&e, (struct pack_backend *)backend, oid)) < 0)
377
+ return error;
378
+
379
+ now = time(NULL);
380
+
381
+ if (e.p->last_freshen > now - FRESHEN_FREQUENCY)
382
+ return 0;
383
+
384
+ if ((error = git_futils_touch(e.p->pack_name, &now)) < 0)
385
+ return error;
386
+
387
+ e.p->last_freshen = now;
388
+ return 0;
389
+ }
390
+
366
391
  static int pack_backend__read(
367
392
  void **buffer_p, size_t *len_p, git_otype *type_p,
368
393
  git_odb_backend *backend, const git_oid *oid)
@@ -560,6 +585,7 @@ static int pack_backend__alloc(struct pack_backend **out, size_t initial_size)
560
585
  backend->parent.refresh = &pack_backend__refresh;
561
586
  backend->parent.foreach = &pack_backend__foreach;
562
587
  backend->parent.writepack = &pack_backend__writepack;
588
+ backend->parent.freshen = &pack_backend__freshen;
563
589
  backend->parent.free = &pack_backend__free;
564
590
 
565
591
  *out = backend;
@@ -164,7 +164,7 @@ int git_openssl_set_locking(void)
164
164
  git__on_shutdown(shutdown_ssl_locking);
165
165
  return 0;
166
166
  #else
167
- giterr_set(GITERR_THREAD, "libgit2 as not built with threads");
167
+ giterr_set(GITERR_THREAD, "libgit2 was not built with threads");
168
168
  return -1;
169
169
  #endif
170
170
  }
@@ -515,11 +515,11 @@ int openssl_certificate(git_cert **out, git_stream *stream)
515
515
  return 0;
516
516
  }
517
517
 
518
- static int openssl_set_proxy(git_stream *stream, const char *proxy_url)
518
+ static int openssl_set_proxy(git_stream *stream, const git_proxy_options *proxy_opts)
519
519
  {
520
520
  openssl_stream *st = (openssl_stream *) stream;
521
521
 
522
- return git_stream_set_proxy(st->io, proxy_url);
522
+ return git_stream_set_proxy(st->io, proxy_opts);
523
523
  }
524
524
 
525
525
  ssize_t openssl_write(git_stream *stream, const char *data, size_t len, int flags)
@@ -541,9 +541,8 @@ ssize_t openssl_read(git_stream *stream, void *data, size_t len)
541
541
  openssl_stream *st = (openssl_stream *) stream;
542
542
  int ret;
543
543
 
544
- if ((ret = SSL_read(st->ssl, data, len)) <= 0) {
544
+ if ((ret = SSL_read(st->ssl, data, len)) <= 0)
545
545
  return ssl_set_error(st->ssl, ret);
546
- }
547
546
 
548
547
  return ret;
549
548
  }