rugged 1.5.1 → 1.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (154) hide show
  1. checksums.yaml +4 -4
  2. data/ext/rugged/extconf.rb +2 -2
  3. data/ext/rugged/rugged_blame.c +2 -0
  4. data/ext/rugged/rugged_blob.c +3 -0
  5. data/ext/rugged/rugged_commit.c +1 -0
  6. data/ext/rugged/rugged_config.c +2 -0
  7. data/ext/rugged/rugged_diff.c +1 -0
  8. data/ext/rugged/rugged_index.c +2 -0
  9. data/ext/rugged/rugged_patch.c +1 -0
  10. data/ext/rugged/rugged_rebase.c +1 -0
  11. data/ext/rugged/rugged_reference.c +1 -0
  12. data/ext/rugged/rugged_remote.c +1 -0
  13. data/ext/rugged/rugged_repo.c +5 -2
  14. data/ext/rugged/rugged_revwalk.c +5 -1
  15. data/ext/rugged/rugged_submodule.c +1 -0
  16. data/ext/rugged/rugged_tag.c +1 -0
  17. data/ext/rugged/rugged_tree.c +4 -0
  18. data/lib/rugged/index.rb +1 -1
  19. data/lib/rugged/tree.rb +1 -1
  20. data/lib/rugged/version.rb +1 -1
  21. data/vendor/libgit2/CMakeLists.txt +5 -1
  22. data/vendor/libgit2/COPYING +30 -0
  23. data/vendor/libgit2/cmake/ExperimentalFeatures.cmake +23 -0
  24. data/vendor/libgit2/deps/ntlmclient/CMakeLists.txt +2 -0
  25. data/vendor/libgit2/include/git2/common.h +13 -6
  26. data/vendor/libgit2/include/git2/deprecated.h +6 -0
  27. data/vendor/libgit2/include/git2/diff.h +1 -1
  28. data/vendor/libgit2/include/git2/experimental.h +20 -0
  29. data/vendor/libgit2/include/git2/indexer.h +29 -0
  30. data/vendor/libgit2/include/git2/object.h +28 -2
  31. data/vendor/libgit2/include/git2/odb.h +58 -7
  32. data/vendor/libgit2/include/git2/odb_backend.h +106 -18
  33. data/vendor/libgit2/include/git2/oid.h +115 -15
  34. data/vendor/libgit2/include/git2/repository.h +20 -1
  35. data/vendor/libgit2/include/git2/stash.h +60 -6
  36. data/vendor/libgit2/include/git2/strarray.h +0 -13
  37. data/vendor/libgit2/include/git2/sys/odb_backend.h +1 -1
  38. data/vendor/libgit2/include/git2/sys/transport.h +12 -0
  39. data/vendor/libgit2/include/git2/version.h +4 -4
  40. data/vendor/libgit2/include/git2.h +1 -0
  41. data/vendor/libgit2/src/CMakeLists.txt +0 -6
  42. data/vendor/libgit2/src/cli/CMakeLists.txt +6 -2
  43. data/vendor/libgit2/src/cli/cmd_hash_object.c +27 -8
  44. data/vendor/libgit2/src/cli/opt.c +1 -1
  45. data/vendor/libgit2/src/libgit2/CMakeLists.txt +25 -15
  46. data/vendor/libgit2/src/libgit2/annotated_commit.c +1 -1
  47. data/vendor/libgit2/src/libgit2/annotated_commit.h +1 -1
  48. data/vendor/libgit2/src/libgit2/attr_file.c +1 -1
  49. data/vendor/libgit2/src/libgit2/attrcache.c +1 -1
  50. data/vendor/libgit2/src/libgit2/blame.c +2 -0
  51. data/vendor/libgit2/src/libgit2/blob.c +4 -2
  52. data/vendor/libgit2/src/libgit2/blob.h +2 -2
  53. data/vendor/libgit2/src/libgit2/branch.c +2 -2
  54. data/vendor/libgit2/src/libgit2/cherrypick.c +3 -3
  55. data/vendor/libgit2/src/libgit2/clone.c +31 -2
  56. data/vendor/libgit2/src/libgit2/commit.c +52 -17
  57. data/vendor/libgit2/src/libgit2/commit.h +25 -7
  58. data/vendor/libgit2/src/libgit2/commit_graph.c +47 -32
  59. data/vendor/libgit2/src/libgit2/commit_graph.h +3 -0
  60. data/vendor/libgit2/src/libgit2/commit_list.c +6 -2
  61. data/vendor/libgit2/src/libgit2/config.c +1 -1
  62. data/vendor/libgit2/src/libgit2/config_file.c +2 -2
  63. data/vendor/libgit2/src/libgit2/describe.c +8 -8
  64. data/vendor/libgit2/src/libgit2/diff.c +5 -1
  65. data/vendor/libgit2/src/libgit2/diff_file.c +15 -6
  66. data/vendor/libgit2/src/libgit2/diff_generate.c +17 -12
  67. data/vendor/libgit2/src/libgit2/diff_print.c +5 -5
  68. data/vendor/libgit2/src/libgit2/diff_tform.c +4 -0
  69. data/vendor/libgit2/src/libgit2/email.c +2 -2
  70. data/vendor/libgit2/src/libgit2/experimental.h.in +13 -0
  71. data/vendor/libgit2/src/libgit2/fetch.c +3 -6
  72. data/vendor/libgit2/src/libgit2/fetchhead.c +4 -4
  73. data/vendor/libgit2/src/libgit2/ident.c +3 -3
  74. data/vendor/libgit2/src/libgit2/index.c +11 -9
  75. data/vendor/libgit2/src/libgit2/indexer.c +107 -44
  76. data/vendor/libgit2/src/libgit2/iterator.c +4 -2
  77. data/vendor/libgit2/src/libgit2/libgit2.c +19 -0
  78. data/vendor/libgit2/src/libgit2/merge.c +3 -3
  79. data/vendor/libgit2/src/libgit2/midx.c +16 -15
  80. data/vendor/libgit2/src/libgit2/mwindow.c +5 -2
  81. data/vendor/libgit2/src/libgit2/mwindow.h +4 -1
  82. data/vendor/libgit2/src/libgit2/notes.c +5 -5
  83. data/vendor/libgit2/src/libgit2/object.c +89 -25
  84. data/vendor/libgit2/src/libgit2/object.h +12 -3
  85. data/vendor/libgit2/src/libgit2/odb.c +194 -50
  86. data/vendor/libgit2/src/libgit2/odb.h +43 -4
  87. data/vendor/libgit2/src/libgit2/odb_loose.c +128 -70
  88. data/vendor/libgit2/src/libgit2/odb_pack.c +96 -44
  89. data/vendor/libgit2/src/libgit2/oid.c +134 -76
  90. data/vendor/libgit2/src/libgit2/oid.h +183 -9
  91. data/vendor/libgit2/src/libgit2/pack-objects.c +15 -4
  92. data/vendor/libgit2/src/libgit2/pack.c +90 -66
  93. data/vendor/libgit2/src/libgit2/pack.h +29 -15
  94. data/vendor/libgit2/src/libgit2/parse.c +4 -3
  95. data/vendor/libgit2/src/libgit2/patch_parse.c +5 -5
  96. data/vendor/libgit2/src/libgit2/push.c +13 -3
  97. data/vendor/libgit2/src/libgit2/reader.c +1 -1
  98. data/vendor/libgit2/src/libgit2/rebase.c +19 -18
  99. data/vendor/libgit2/src/libgit2/refdb_fs.c +70 -39
  100. data/vendor/libgit2/src/libgit2/reflog.c +7 -5
  101. data/vendor/libgit2/src/libgit2/reflog.h +1 -2
  102. data/vendor/libgit2/src/libgit2/refs.c +2 -0
  103. data/vendor/libgit2/src/libgit2/remote.c +38 -37
  104. data/vendor/libgit2/src/libgit2/remote.h +40 -0
  105. data/vendor/libgit2/src/libgit2/repository.c +212 -36
  106. data/vendor/libgit2/src/libgit2/repository.h +9 -0
  107. data/vendor/libgit2/src/libgit2/reset.c +2 -2
  108. data/vendor/libgit2/src/libgit2/revert.c +4 -4
  109. data/vendor/libgit2/src/libgit2/revparse.c +23 -7
  110. data/vendor/libgit2/src/libgit2/revwalk.c +5 -1
  111. data/vendor/libgit2/src/libgit2/stash.c +201 -26
  112. data/vendor/libgit2/src/libgit2/strarray.c +1 -0
  113. data/vendor/libgit2/src/libgit2/strarray.h +25 -0
  114. data/vendor/libgit2/src/libgit2/streams/openssl.c +1 -1
  115. data/vendor/libgit2/src/libgit2/streams/openssl_dynamic.c +7 -3
  116. data/vendor/libgit2/src/libgit2/streams/socket.c +4 -1
  117. data/vendor/libgit2/src/libgit2/submodule.c +6 -2
  118. data/vendor/libgit2/src/libgit2/sysdir.c +294 -7
  119. data/vendor/libgit2/src/libgit2/sysdir.h +39 -9
  120. data/vendor/libgit2/src/libgit2/tag.c +29 -10
  121. data/vendor/libgit2/src/libgit2/tag.h +2 -2
  122. data/vendor/libgit2/src/libgit2/threadstate.h +1 -1
  123. data/vendor/libgit2/src/libgit2/transports/http.c +8 -7
  124. data/vendor/libgit2/src/libgit2/transports/httpclient.c +9 -0
  125. data/vendor/libgit2/src/libgit2/transports/httpclient.h +10 -0
  126. data/vendor/libgit2/src/libgit2/transports/local.c +14 -0
  127. data/vendor/libgit2/src/libgit2/transports/smart.c +35 -0
  128. data/vendor/libgit2/src/libgit2/transports/smart.h +10 -1
  129. data/vendor/libgit2/src/libgit2/transports/smart_pkt.c +153 -41
  130. data/vendor/libgit2/src/libgit2/transports/smart_protocol.c +42 -12
  131. data/vendor/libgit2/src/libgit2/transports/ssh.c +62 -65
  132. data/vendor/libgit2/src/libgit2/transports/winhttp.c +9 -4
  133. data/vendor/libgit2/src/libgit2/tree-cache.c +4 -4
  134. data/vendor/libgit2/src/libgit2/tree.c +22 -16
  135. data/vendor/libgit2/src/libgit2/tree.h +2 -2
  136. data/vendor/libgit2/src/libgit2/worktree.c +5 -0
  137. data/vendor/libgit2/src/util/CMakeLists.txt +7 -1
  138. data/vendor/libgit2/src/util/fs_path.c +1 -1
  139. data/vendor/libgit2/src/util/futils.c +0 -3
  140. data/vendor/libgit2/src/util/git2_util.h +2 -2
  141. data/vendor/libgit2/src/util/hash/openssl.c +4 -3
  142. data/vendor/libgit2/src/util/hash/rfc6234/sha.h +0 -112
  143. data/vendor/libgit2/src/util/hash.h +13 -0
  144. data/vendor/libgit2/src/util/net.c +338 -84
  145. data/vendor/libgit2/src/util/net.h +7 -0
  146. data/vendor/libgit2/src/util/posix.h +2 -0
  147. data/vendor/libgit2/src/util/rand.c +4 -0
  148. data/vendor/libgit2/src/util/regexp.c +3 -3
  149. data/vendor/libgit2/src/util/thread.h +20 -19
  150. data/vendor/libgit2/src/util/util.h +1 -0
  151. metadata +7 -5
  152. data/vendor/libgit2/src/util/win32/findfile.c +0 -286
  153. data/vendor/libgit2/src/util/win32/findfile.h +0 -22
  154. /data/vendor/libgit2/src/{features.h.in → util/git2_features.h.in} +0 -0
@@ -32,7 +32,7 @@ static int packfile_unpack_compressed(
32
32
  * Throws GIT_EAMBIGUOUSOIDPREFIX if short oid
33
33
  * is ambiguous within the pack.
34
34
  * This method assumes that len is between
35
- * GIT_OID_MINPREFIXLEN and GIT_OID_HEXSZ.
35
+ * GIT_OID_MINPREFIXLEN and the oid type's hexsize.
36
36
  */
37
37
  static int pack_entry_find_offset(
38
38
  off64_t *offset_out,
@@ -186,9 +186,9 @@ static int cache_add(
186
186
 
187
187
  static void pack_index_free(struct git_pack_file *p)
188
188
  {
189
- if (p->oids) {
190
- git__free(p->oids);
191
- p->oids = NULL;
189
+ if (p->ids) {
190
+ git__free(p->ids);
191
+ p->ids = NULL;
192
192
  }
193
193
  if (p->index_map.data) {
194
194
  git_futils_mmap_free(&p->index_map);
@@ -205,6 +205,7 @@ static int pack_index_check_locked(const char *path, struct git_pack_file *p)
205
205
  size_t idx_size;
206
206
  struct stat st;
207
207
  int error;
208
+
208
209
  /* TODO: properly open the file without access time using O_NOATIME */
209
210
  git_file fd = git_futils_open_ro(path);
210
211
  if (fd < 0)
@@ -218,8 +219,7 @@ static int pack_index_check_locked(const char *path, struct git_pack_file *p)
218
219
 
219
220
  if (!S_ISREG(st.st_mode) ||
220
221
  !git__is_sizet(st.st_size) ||
221
- (idx_size = (size_t)st.st_size) < 4 * 256 + 20 + 20)
222
- {
222
+ (idx_size = (size_t)st.st_size) < (size_t)((4 * 256) + (p->oid_size * 2))) {
223
223
  p_close(fd);
224
224
  git_error_set(GIT_ERROR_ODB, "invalid pack index '%s'", path);
225
225
  return -1;
@@ -242,8 +242,9 @@ static int pack_index_check_locked(const char *path, struct git_pack_file *p)
242
242
  return packfile_error("unsupported index version");
243
243
  }
244
244
 
245
- } else
245
+ } else {
246
246
  version = 1;
247
+ }
247
248
 
248
249
  nr = 0;
249
250
  index = idx_map;
@@ -264,11 +265,11 @@ static int pack_index_check_locked(const char *path, struct git_pack_file *p)
264
265
  /*
265
266
  * Total size:
266
267
  * - 256 index entries 4 bytes each
267
- * - 24-byte entries * nr (20-byte sha1 + 4-byte offset)
268
- * - 20-byte SHA1 of the packfile
269
- * - 20-byte SHA1 file checksum
268
+ * - 24/36-byte entries * nr (20/32 byte SHA + 4-byte offset)
269
+ * - 20/32-byte SHA of the packfile
270
+ * - 20/32-byte SHA file checksum
270
271
  */
271
- if (idx_size != 4*256 + nr * 24 + 20 + 20) {
272
+ if (idx_size != (4 * 256 + (nr * (p->oid_size + 4)) + (p->oid_size * 2))) {
272
273
  git_futils_mmap_free(&p->index_map);
273
274
  return packfile_error("index is corrupted");
274
275
  }
@@ -277,16 +278,16 @@ static int pack_index_check_locked(const char *path, struct git_pack_file *p)
277
278
  * Minimum size:
278
279
  * - 8 bytes of header
279
280
  * - 256 index entries 4 bytes each
280
- * - 20-byte sha1 entry * nr
281
+ * - 20/32-byte SHA entry * nr
281
282
  * - 4-byte crc entry * nr
282
283
  * - 4-byte offset entry * nr
283
- * - 20-byte SHA1 of the packfile
284
- * - 20-byte SHA1 file checksum
284
+ * - 20/32-byte SHA of the packfile
285
+ * - 20/32-byte SHA file checksum
285
286
  * And after the 4-byte offset table might be a
286
287
  * variable sized table containing 8-byte entries
287
288
  * for offsets larger than 2^31.
288
289
  */
289
- unsigned long min_size = 8 + 4*256 + nr*(20 + 4 + 4) + 20 + 20;
290
+ unsigned long min_size = 8 + (4 * 256) + (nr * (p->oid_size + 4 + 4)) + (p->oid_size * 2);
290
291
  unsigned long max_size = min_size;
291
292
 
292
293
  if (nr)
@@ -365,12 +366,12 @@ static unsigned char *pack_window_open(
365
366
  * Don't allow a negative offset, as that means we've wrapped
366
367
  * around.
367
368
  */
368
- if (offset > (p->mwf.size - 20))
369
+ if (offset > (p->mwf.size - p->oid_size))
369
370
  goto cleanup;
370
371
  if (offset < 0)
371
372
  goto cleanup;
372
373
 
373
- pack_data = git_mwindow_open(&p->mwf, w_cursor, offset, 20, left);
374
+ pack_data = git_mwindow_open(&p->mwf, w_cursor, offset, p->oid_size, left);
374
375
 
375
376
  cleanup:
376
377
  git_mutex_unlock(&p->mwf.lock);
@@ -473,13 +474,13 @@ int git_packfile_unpack_header(
473
474
  return error;
474
475
  }
475
476
 
476
- /* pack_window_open() assures us we have [base, base + 20) available
477
- * as a range that we can look at at. (Its actually the hash
478
- * size that is assured.) With our object header encoding
479
- * the maximum deflated object size is 2^137, which is just
480
- * insane, so we know won't exceed what we have been given.
477
+ /* pack_window_open() assures us we have [base, base + oid_size)
478
+ * available as a range that we can look at at. (It's actually
479
+ * the hash size that is assured.) With our object header
480
+ * encoding the maximum deflated object size is 2^137, which is
481
+ * just insane, so we know won't exceed what we have been given.
481
482
  */
482
- base = git_mwindow_open(&p->mwf, w_curs, *curpos, 20, &left);
483
+ base = git_mwindow_open(&p->mwf, w_curs, *curpos, p->oid_size, &left);
483
484
  git_mutex_unlock(&p->lock);
484
485
  git_mutex_unlock(&p->mwf.lock);
485
486
  if (base == NULL)
@@ -977,11 +978,12 @@ int get_delta_base(
977
978
  /* Assumption: the only reason this would fail is because the file is too small */
978
979
  if (base_info == NULL)
979
980
  return GIT_EBUFS;
980
- /* pack_window_open() assured us we have [base_info, base_info + 20)
981
- * as a range that we can look at without walking off the
982
- * end of the mapped window. Its actually the hash size
983
- * that is assured. An OFS_DELTA longer than the hash size
984
- * is stupid, as then a REF_DELTA would be smaller to store.
981
+ /* pack_window_open() assured us we have
982
+ * [base_info, base_info + oid_size) as a range that we can look
983
+ * at without walking off the end of the mapped window. Its
984
+ * actually the hash size that is assured. An OFS_DELTA longer
985
+ * than the hash size is stupid, as then a REF_DELTA would be
986
+ * smaller to store.
985
987
  */
986
988
  if (type == GIT_OBJECT_OFS_DELTA) {
987
989
  unsigned used = 0;
@@ -1002,7 +1004,7 @@ int get_delta_base(
1002
1004
  *curpos += used;
1003
1005
  } else if (type == GIT_OBJECT_REF_DELTA) {
1004
1006
  git_oid base_oid;
1005
- git_oid_fromraw(&base_oid, base_info);
1007
+ git_oid__fromraw(&base_oid, base_info, p->oid_type);
1006
1008
 
1007
1009
  /* If we have the cooperative cache, search in it first */
1008
1010
  if (p->has_cache) {
@@ -1012,7 +1014,7 @@ int get_delta_base(
1012
1014
  if (entry->offset == 0)
1013
1015
  return packfile_error("delta offset is zero");
1014
1016
 
1015
- *curpos += 20;
1017
+ *curpos += p->oid_size;
1016
1018
  *delta_base_out = entry->offset;
1017
1019
  return 0;
1018
1020
  } else {
@@ -1025,9 +1027,9 @@ int get_delta_base(
1025
1027
  }
1026
1028
 
1027
1029
  /* The base entry _must_ be in the same pack */
1028
- if (pack_entry_find_offset(&base_offset, &unused, p, &base_oid, GIT_OID_HEXSZ) < 0)
1030
+ if (pack_entry_find_offset(&base_offset, &unused, p, &base_oid, p->oid_hexsize) < 0)
1029
1031
  return packfile_error("base entry delta is not in the same pack");
1030
- *curpos += 20;
1032
+ *curpos += p->oid_size;
1031
1033
  } else
1032
1034
  return packfile_error("unknown object type");
1033
1035
 
@@ -1070,7 +1072,7 @@ void git_packfile_free(struct git_pack_file *p, bool unlink_packfile)
1070
1072
 
1071
1073
  pack_index_free(p);
1072
1074
 
1073
- git__free(p->bad_object_sha1);
1075
+ git__free(p->bad_object_ids);
1074
1076
 
1075
1077
  git_mutex_free(&p->bases.lock);
1076
1078
  git_mutex_free(&p->mwf.lock);
@@ -1083,8 +1085,8 @@ static int packfile_open_locked(struct git_pack_file *p)
1083
1085
  {
1084
1086
  struct stat st;
1085
1087
  struct git_pack_header hdr;
1086
- unsigned char sha1[GIT_OID_RAWSZ];
1087
- unsigned char *idx_sha1;
1088
+ unsigned char checksum[GIT_OID_MAX_SIZE];
1089
+ unsigned char *idx_checksum;
1088
1090
 
1089
1091
  if (pack_index_open_locked(p) < 0)
1090
1092
  return git_odb__error_notfound("failed to open packfile", NULL, 0);
@@ -1131,12 +1133,13 @@ static int packfile_open_locked(struct git_pack_file *p)
1131
1133
 
1132
1134
  /* Verify the pack matches its index. */
1133
1135
  if (p->num_objects != ntohl(hdr.hdr_entries) ||
1134
- p_pread(p->mwf.fd, sha1, GIT_OID_RAWSZ, p->mwf.size - GIT_OID_RAWSZ) < 0)
1136
+ p_pread(p->mwf.fd, checksum, p->oid_size, p->mwf.size - p->oid_size) < 0)
1135
1137
  goto cleanup;
1136
1138
 
1137
- idx_sha1 = ((unsigned char *)p->index_map.data) + p->index_map.len - 40;
1139
+ idx_checksum = ((unsigned char *)p->index_map.data) +
1140
+ p->index_map.len - (p->oid_size * 2);
1138
1141
 
1139
- if (git_oid_raw_cmp(sha1, idx_sha1) != 0)
1142
+ if (git_oid_raw_cmp(checksum, idx_checksum, p->oid_size) != 0)
1140
1143
  goto cleanup;
1141
1144
 
1142
1145
  if (git_mwindow_file_register(&p->mwf) < 0)
@@ -1171,7 +1174,10 @@ int git_packfile__name(char **out, const char *path)
1171
1174
  return 0;
1172
1175
  }
1173
1176
 
1174
- int git_packfile_alloc(struct git_pack_file **pack_out, const char *path)
1177
+ int git_packfile_alloc(
1178
+ struct git_pack_file **pack_out,
1179
+ const char *path,
1180
+ git_oid_t oid_type)
1175
1181
  {
1176
1182
  struct stat st;
1177
1183
  struct git_pack_file *p;
@@ -1219,6 +1225,9 @@ int git_packfile_alloc(struct git_pack_file **pack_out, const char *path)
1219
1225
  p->pack_local = 1;
1220
1226
  p->mtime = (git_time_t)st.st_mtime;
1221
1227
  p->index_version = -1;
1228
+ p->oid_type = oid_type ? oid_type : GIT_OID_DEFAULT;
1229
+ p->oid_size = (unsigned int)git_oid_size(p->oid_type);
1230
+ p->oid_hexsize = (unsigned int)git_oid_hexsize(p->oid_type);
1222
1231
 
1223
1232
  if (git_mutex_init(&p->lock) < 0) {
1224
1233
  git_error_set(GIT_ERROR_OS, "failed to initialize packfile mutex");
@@ -1260,9 +1269,9 @@ static off64_t nth_packed_object_offset_locked(struct git_pack_file *p, uint32_t
1260
1269
  end = index + p->index_map.len;
1261
1270
  index += 4 * 256;
1262
1271
  if (p->index_version == 1)
1263
- return ntohl(*((uint32_t *)(index + 24 * n)));
1272
+ return ntohl(*((uint32_t *)(index + (p->oid_size + 4) * n)));
1264
1273
 
1265
- index += 8 + p->num_objects * (20 + 4);
1274
+ index += 8 + p->num_objects * (p->oid_size + 4);
1266
1275
  off32 = ntohl(*((uint32_t *)(index + 4 * n)));
1267
1276
  if (!(off32 & 0x80000000))
1268
1277
  return off32;
@@ -1273,7 +1282,7 @@ static off64_t nth_packed_object_offset_locked(struct git_pack_file *p, uint32_t
1273
1282
  return -1;
1274
1283
 
1275
1284
  return (((uint64_t)ntohl(*((uint32_t *)(index + 0)))) << 32) |
1276
- ntohl(*((uint32_t *)(index + 4)));
1285
+ ntohl(*((uint32_t *)(index + 4)));
1277
1286
  }
1278
1287
 
1279
1288
  static int git__memcmp4(const void *a, const void *b) {
@@ -1312,7 +1321,7 @@ int git_pack_foreach_entry(
1312
1321
 
1313
1322
  index += 4 * 256;
1314
1323
 
1315
- if (p->oids == NULL) {
1324
+ if (p->ids == NULL) {
1316
1325
  git_vector offsets, oids;
1317
1326
 
1318
1327
  if ((error = git_vector_init(&oids, p->num_objects, NULL))) {
@@ -1326,22 +1335,25 @@ int git_pack_foreach_entry(
1326
1335
  }
1327
1336
 
1328
1337
  if (p->index_version > 1) {
1329
- const unsigned char *off = index + 24 * p->num_objects;
1338
+ const unsigned char *off = index +
1339
+ (p->oid_size + 4) * p->num_objects;
1340
+
1330
1341
  for (i = 0; i < p->num_objects; i++)
1331
1342
  git_vector_insert(&offsets, (void*)&off[4 * i]);
1343
+
1332
1344
  git_vector_sort(&offsets);
1333
1345
  git_vector_foreach(&offsets, i, current)
1334
1346
  git_vector_insert(&oids, (void*)&index[5 * (current - off)]);
1335
1347
  } else {
1336
1348
  for (i = 0; i < p->num_objects; i++)
1337
- git_vector_insert(&offsets, (void*)&index[24 * i]);
1349
+ git_vector_insert(&offsets, (void*)&index[(p->oid_size + 4) * i]);
1338
1350
  git_vector_sort(&offsets);
1339
1351
  git_vector_foreach(&offsets, i, current)
1340
1352
  git_vector_insert(&oids, (void*)&current[4]);
1341
1353
  }
1342
1354
 
1343
1355
  git_vector_free(&offsets);
1344
- p->oids = (unsigned char **)git_vector_detach(NULL, NULL, &oids);
1356
+ p->ids = (unsigned char **)git_vector_detach(NULL, NULL, &oids);
1345
1357
  }
1346
1358
 
1347
1359
  /*
@@ -1362,7 +1374,7 @@ int git_pack_foreach_entry(
1362
1374
  git_array_clear(oids);
1363
1375
  GIT_ERROR_CHECK_ALLOC(oid);
1364
1376
  }
1365
- git_oid_fromraw(oid, p->oids[i]);
1377
+ git_oid__fromraw(oid, p->ids[i], p->oid_type);
1366
1378
  }
1367
1379
 
1368
1380
  git_mutex_unlock(&p->lock);
@@ -1412,10 +1424,13 @@ int git_pack_foreach_entry_offset(
1412
1424
 
1413
1425
  /* all offsets should have been validated by pack_index_check_locked */
1414
1426
  if (p->index_version > 1) {
1415
- const unsigned char *offsets = index + 24 * p->num_objects;
1427
+ const unsigned char *offsets = index +
1428
+ (p->oid_size + 4) * p->num_objects;
1416
1429
  const unsigned char *large_offset_ptr;
1417
- const unsigned char *large_offsets = index + 28 * p->num_objects;
1418
- const unsigned char *large_offsets_end = ((const unsigned char *)p->index_map.data) + p->index_map.len - 20;
1430
+ const unsigned char *large_offsets = index +
1431
+ (p->oid_size + 8) * p->num_objects;
1432
+ const unsigned char *large_offsets_end = ((const unsigned char *)p->index_map.data) + p->index_map.len - p->oid_size;
1433
+
1419
1434
  for (i = 0; i < p->num_objects; i++) {
1420
1435
  current_offset = ntohl(*(const uint32_t *)(offsets + 4 * i));
1421
1436
  if (current_offset & 0x80000000) {
@@ -1428,7 +1443,7 @@ int git_pack_foreach_entry_offset(
1428
1443
  ntohl(*((uint32_t *)(large_offset_ptr + 4)));
1429
1444
  }
1430
1445
 
1431
- git_oid_fromraw(&current_oid, (index + 20 * i));
1446
+ git_oid__fromraw(&current_oid, (index + p->oid_size * i), p->oid_type);
1432
1447
  if ((error = cb(&current_oid, current_offset, data)) != 0) {
1433
1448
  error = git_error_set_after_callback(error);
1434
1449
  goto cleanup;
@@ -1436,8 +1451,8 @@ int git_pack_foreach_entry_offset(
1436
1451
  }
1437
1452
  } else {
1438
1453
  for (i = 0; i < p->num_objects; i++) {
1439
- current_offset = ntohl(*(const uint32_t *)(index + 24 * i));
1440
- git_oid_fromraw(&current_oid, (index + 24 * i + 4));
1454
+ current_offset = ntohl(*(const uint32_t *)(index + (p->oid_size + 4) * i));
1455
+ git_oid__fromraw(&current_oid, (index + (p->oid_size + 4) * i + 4), p->oid_type);
1441
1456
  if ((error = cb(&current_oid, current_offset, data)) != 0) {
1442
1457
  error = git_error_set_after_callback(error);
1443
1458
  goto cleanup;
@@ -1450,14 +1465,20 @@ cleanup:
1450
1465
  return error;
1451
1466
  }
1452
1467
 
1453
- int git_pack__lookup_sha1(const void *oid_lookup_table, size_t stride, unsigned lo,
1454
- unsigned hi, const unsigned char *oid_prefix)
1468
+ int git_pack__lookup_id(
1469
+ const void *oid_lookup_table,
1470
+ size_t stride,
1471
+ unsigned lo,
1472
+ unsigned hi,
1473
+ const unsigned char *oid_prefix,
1474
+ const git_oid_t oid_type)
1455
1475
  {
1456
1476
  const unsigned char *base = oid_lookup_table;
1477
+ size_t oid_size = git_oid_size(oid_type);
1457
1478
 
1458
1479
  while (lo < hi) {
1459
1480
  unsigned mi = (lo + hi) / 2;
1460
- int cmp = git_oid_raw_cmp(base + mi * stride, oid_prefix);
1481
+ int cmp = git_oid_raw_cmp(base + mi * stride, oid_prefix, oid_size);
1461
1482
 
1462
1483
  if (!cmp)
1463
1484
  return mi;
@@ -1512,9 +1533,9 @@ static int pack_entry_find_offset(
1512
1533
  lo = ((short_oid->id[0] == 0x0) ? 0 : ntohl(level1_ofs[(int)short_oid->id[0] - 1]));
1513
1534
 
1514
1535
  if (p->index_version > 1) {
1515
- stride = 20;
1536
+ stride = p->oid_size;
1516
1537
  } else {
1517
- stride = 24;
1538
+ stride = p->oid_size + 4;
1518
1539
  index += 4;
1519
1540
  }
1520
1541
 
@@ -1523,7 +1544,8 @@ static int pack_entry_find_offset(
1523
1544
  short_oid->id[0], short_oid->id[1], short_oid->id[2], lo, hi, p->num_objects);
1524
1545
  #endif
1525
1546
 
1526
- pos = git_pack__lookup_sha1(index, stride, lo, hi, short_oid->id);
1547
+ pos = git_pack__lookup_id(index, stride, lo, hi,
1548
+ short_oid->id, p->oid_type);
1527
1549
 
1528
1550
  if (pos >= 0) {
1529
1551
  /* An object matching exactly the oid was found */
@@ -1541,7 +1563,9 @@ static int pack_entry_find_offset(
1541
1563
  }
1542
1564
  }
1543
1565
 
1544
- if (found && len != GIT_OID_HEXSZ && pos + 1 < (int)p->num_objects) {
1566
+ if (found &&
1567
+ len != p->oid_hexsize &&
1568
+ pos + 1 < (int)p->num_objects) {
1545
1569
  /* Check for ambiguousity */
1546
1570
  const unsigned char *next = current + stride;
1547
1571
 
@@ -1566,13 +1590,13 @@ static int pack_entry_find_offset(
1566
1590
  }
1567
1591
 
1568
1592
  *offset_out = offset;
1569
- git_oid_fromraw(found_oid, current);
1593
+ git_oid__fromraw(found_oid, current, p->oid_type);
1570
1594
 
1571
1595
  #ifdef INDEX_DEBUG_LOOKUP
1572
1596
  {
1573
- unsigned char hex_sha1[GIT_OID_HEXSZ + 1];
1597
+ char hex_sha1[p->oid_hexsize + 1];
1574
1598
  git_oid_fmt(hex_sha1, found_oid);
1575
- hex_sha1[GIT_OID_HEXSZ] = '\0';
1599
+ hex_sha1[p->oid_hexsize] = '\0';
1576
1600
  printf("found lo=%d %s\n", lo, hex_sha1);
1577
1601
  }
1578
1602
  #endif
@@ -1594,10 +1618,10 @@ int git_pack_entry_find(
1594
1618
 
1595
1619
  GIT_ASSERT_ARG(p);
1596
1620
 
1597
- if (len == GIT_OID_HEXSZ && p->num_bad_objects) {
1621
+ if (len == p->oid_hexsize && p->num_bad_objects) {
1598
1622
  unsigned i;
1599
1623
  for (i = 0; i < p->num_bad_objects; i++)
1600
- if (git_oid__cmp(short_oid, &p->bad_object_sha1[i]) == 0)
1624
+ if (git_oid__cmp(short_oid, &p->bad_object_ids[i]) == 0)
1601
1625
  return packfile_error("bad object found in packfile");
1602
1626
  }
1603
1627
 
@@ -1630,6 +1654,6 @@ int git_pack_entry_find(
1630
1654
  e->offset = offset;
1631
1655
  e->p = p;
1632
1656
 
1633
- git_oid_cpy(&e->sha1, &found_oid);
1657
+ git_oid_cpy(&e->id, &found_oid);
1634
1658
  return 0;
1635
1659
  }
@@ -99,13 +99,19 @@ struct git_pack_file {
99
99
 
100
100
  uint32_t num_objects;
101
101
  uint32_t num_bad_objects;
102
- git_oid *bad_object_sha1; /* array of git_oid */
102
+ git_oid *bad_object_ids; /* array of git_oid */
103
+
104
+ git_oid_t oid_type;
105
+ unsigned oid_hexsize:7,
106
+ oid_size:6,
107
+ pack_local:1,
108
+ pack_keep:1,
109
+ has_cache:1;
103
110
 
104
111
  int index_version;
105
112
  git_time_t mtime;
106
- unsigned pack_local:1, pack_keep:1, has_cache:1;
107
113
  git_oidmap *idx_cache;
108
- unsigned char **oids;
114
+ unsigned char **ids;
109
115
 
110
116
  git_pack_cache bases; /* delta base cache */
111
117
 
@@ -116,21 +122,26 @@ struct git_pack_file {
116
122
  };
117
123
 
118
124
  /**
119
- * Return the position where an OID (or a prefix) would be inserted within the
120
- * OID Lookup Table of an .idx file. This performs binary search between the lo
121
- * and hi indices.
125
+ * Return the position where an OID (or a prefix) would be inserted within
126
+ * the OID Lookup Table of an .idx file. This performs binary search
127
+ * between the lo and hi indices.
122
128
  *
123
- * The stride parameter is provided because .idx files version 1 store the OIDs
124
- * interleaved with the 4-byte file offsets of the objects within the .pack
125
- * file (stride = 24), whereas files with version 2 store them in a contiguous
126
- * flat array (stride = 20).
129
+ * The stride parameter is provided because .idx files version 1 store the
130
+ * OIDs interleaved with the 4-byte file offsets of the objects within the
131
+ * .pack file (stride = oid_size + 4), whereas files with version 2 store
132
+ * them in a contiguous flat array (stride = oid_size).
127
133
  */
128
- int git_pack__lookup_sha1(const void *oid_lookup_table, size_t stride, unsigned lo,
129
- unsigned hi, const unsigned char *oid_prefix);
134
+ int git_pack__lookup_id(
135
+ const void *id_lookup_table,
136
+ size_t stride,
137
+ unsigned lo,
138
+ unsigned hi,
139
+ const unsigned char *id_prefix,
140
+ const git_oid_t oid_type);
130
141
 
131
142
  struct git_pack_entry {
132
143
  off64_t offset;
133
- git_oid sha1;
144
+ git_oid id;
134
145
  struct git_pack_file *p;
135
146
  };
136
147
 
@@ -174,12 +185,15 @@ int get_delta_base(
174
185
  off64_t delta_obj_offset);
175
186
 
176
187
  void git_packfile_free(struct git_pack_file *p, bool unlink_packfile);
177
- int git_packfile_alloc(struct git_pack_file **pack_out, const char *path);
188
+ int git_packfile_alloc(
189
+ struct git_pack_file **pack_out,
190
+ const char *path,
191
+ git_oid_t oid_type);
178
192
 
179
193
  int git_pack_entry_find(
180
194
  struct git_pack_entry *e,
181
195
  struct git_pack_file *p,
182
- const git_oid *short_oid,
196
+ const git_oid *short_id,
183
197
  size_t len);
184
198
  int git_pack_foreach_entry(
185
199
  struct git_pack_file *p,
@@ -5,6 +5,7 @@
5
5
  * a Linking Exception. For full terms see the included COPYING file.
6
6
  */
7
7
  #include "parse.h"
8
+ #include "oid.h"
8
9
 
9
10
  int git_parse_ctx_init(git_parse_ctx *ctx, const char *content, size_t content_len)
10
11
  {
@@ -103,11 +104,11 @@ int git_parse_advance_digit(int64_t *out, git_parse_ctx *ctx, int base)
103
104
 
104
105
  int git_parse_advance_oid(git_oid *out, git_parse_ctx *ctx)
105
106
  {
106
- if (ctx->line_len < GIT_OID_HEXSZ)
107
+ if (ctx->line_len < GIT_OID_SHA1_HEXSIZE)
107
108
  return -1;
108
- if ((git_oid_fromstrn(out, ctx->line, GIT_OID_HEXSZ)) < 0)
109
+ if ((git_oid__fromstrn(out, ctx->line, GIT_OID_SHA1_HEXSIZE, GIT_OID_SHA1)) < 0)
109
110
  return -1;
110
- git_parse_advance_chars(ctx, GIT_OID_HEXSZ);
111
+ git_parse_advance_chars(ctx, GIT_OID_SHA1_HEXSIZE);
111
112
  return 0;
112
113
  }
113
114
 
@@ -168,13 +168,13 @@ static int parse_header_oid(
168
168
  {
169
169
  size_t len;
170
170
 
171
- for (len = 0; len < ctx->parse_ctx.line_len && len < GIT_OID_HEXSZ; len++) {
171
+ for (len = 0; len < ctx->parse_ctx.line_len && len < GIT_OID_SHA1_HEXSIZE; len++) {
172
172
  if (!git__isxdigit(ctx->parse_ctx.line[len]))
173
173
  break;
174
174
  }
175
175
 
176
- if (len < GIT_OID_MINPREFIXLEN || len > GIT_OID_HEXSZ ||
177
- git_oid_fromstrn(oid, ctx->parse_ctx.line, len) < 0)
176
+ if (len < GIT_OID_MINPREFIXLEN || len > GIT_OID_SHA1_HEXSIZE ||
177
+ git_oid__fromstrn(oid, ctx->parse_ctx.line, len, GIT_OID_SHA1) < 0)
178
178
  return git_parse_err("invalid hex formatted object id at line %"PRIuZ,
179
179
  ctx->parse_ctx.line_num);
180
180
 
@@ -1065,12 +1065,12 @@ static int check_patch(git_patch_parsed *patch)
1065
1065
  return git_parse_err("patch with no hunks");
1066
1066
 
1067
1067
  if (delta->status == GIT_DELTA_ADDED) {
1068
- memset(&delta->old_file.id, 0x0, sizeof(git_oid));
1068
+ git_oid_clear(&delta->old_file.id, GIT_OID_SHA1);
1069
1069
  delta->old_file.id_abbrev = 0;
1070
1070
  }
1071
1071
 
1072
1072
  if (delta->status == GIT_DELTA_DELETED) {
1073
- memset(&delta->new_file.id, 0x0, sizeof(git_oid));
1073
+ git_oid_clear(&delta->new_file.id, GIT_OID_SHA1);
1074
1074
  delta->new_file.id_abbrev = 0;
1075
1075
  }
1076
1076
 
@@ -118,6 +118,9 @@ static int parse_refspec(git_push *push, push_spec **spec, const char *str)
118
118
  s = git__calloc(1, sizeof(*s));
119
119
  GIT_ERROR_CHECK_ALLOC(s);
120
120
 
121
+ git_oid_clear(&s->loid, GIT_OID_SHA1);
122
+ git_oid_clear(&s->roid, GIT_OID_SHA1);
123
+
121
124
  if (git_refspec__parse(&s->refspec, str, false) < 0) {
122
125
  git_error_set(GIT_ERROR_INVALID, "invalid refspec %s", str);
123
126
  goto on_error;
@@ -382,11 +385,18 @@ static int calculate_work(git_push *push)
382
385
  git_vector_foreach(&push->specs, i, spec) {
383
386
  if (spec->refspec.src && spec->refspec.src[0]!= '\0') {
384
387
  /* This is a create or update. Local ref must exist. */
385
- if (git_reference_name_to_id(
386
- &spec->loid, push->repo, spec->refspec.src) < 0) {
387
- git_error_set(GIT_ERROR_REFERENCE, "no such reference '%s'", spec->refspec.src);
388
+
389
+ git_object *obj;
390
+ int error = git_revparse_single(&obj, push->repo, spec->refspec.src);
391
+
392
+ if (error < 0) {
393
+ git_object_free(obj);
394
+ git_error_set(GIT_ERROR_REFERENCE, "src refspec %s does not match any", spec->refspec.src);
388
395
  return -1;
389
396
  }
397
+
398
+ git_oid_cpy(&spec->loid, git_object_id(obj));
399
+ git_object_free(obj);
390
400
  }
391
401
 
392
402
  /* Remote ref may or may not (e.g. during create) already exist. */
@@ -125,7 +125,7 @@ static int workdir_reader_read(
125
125
  goto done;
126
126
 
127
127
  if (out_id || reader->index) {
128
- if ((error = git_odb_hash(&id, out->ptr, out->size, GIT_OBJECT_BLOB)) < 0)
128
+ if ((error = git_odb__hash(&id, out->ptr, out->size, GIT_OBJECT_BLOB, GIT_OID_SHA1)) < 0)
129
129
  goto done;
130
130
  }
131
131