rugged 1.5.1 → 1.6.2

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -138,19 +138,19 @@ static int commit_graph_parse_oid_lookup(
138
138
  struct git_commit_graph_chunk *chunk_oid_lookup)
139
139
  {
140
140
  uint32_t i;
141
- unsigned char *oid, *prev_oid, zero_oid[GIT_OID_RAWSZ] = {0};
141
+ unsigned char *oid, *prev_oid, zero_oid[GIT_OID_SHA1_SIZE] = {0};
142
142
 
143
143
  if (chunk_oid_lookup->offset == 0)
144
144
  return commit_graph_error("missing OID Lookup chunk");
145
145
  if (chunk_oid_lookup->length == 0)
146
146
  return commit_graph_error("empty OID Lookup chunk");
147
- if (chunk_oid_lookup->length != file->num_commits * GIT_OID_RAWSZ)
147
+ if (chunk_oid_lookup->length != file->num_commits * GIT_OID_SHA1_SIZE)
148
148
  return commit_graph_error("OID Lookup chunk has wrong length");
149
149
 
150
150
  file->oid_lookup = oid = (unsigned char *)(data + chunk_oid_lookup->offset);
151
151
  prev_oid = zero_oid;
152
- for (i = 0; i < file->num_commits; ++i, oid += GIT_OID_RAWSZ) {
153
- if (git_oid_raw_cmp(prev_oid, oid) >= 0)
152
+ for (i = 0; i < file->num_commits; ++i, oid += GIT_OID_SHA1_SIZE) {
153
+ if (git_oid_raw_cmp(prev_oid, oid, GIT_OID_SHA1_SIZE) >= 0)
154
154
  return commit_graph_error("OID Lookup index is non-monotonic");
155
155
  prev_oid = oid;
156
156
  }
@@ -167,7 +167,7 @@ static int commit_graph_parse_commit_data(
167
167
  return commit_graph_error("missing Commit Data chunk");
168
168
  if (chunk_commit_data->length == 0)
169
169
  return commit_graph_error("empty Commit Data chunk");
170
- if (chunk_commit_data->length != file->num_commits * (GIT_OID_RAWSZ + 16))
170
+ if (chunk_commit_data->length != file->num_commits * (GIT_OID_SHA1_SIZE + 16))
171
171
  return commit_graph_error("Commit Data chunk has wrong length");
172
172
 
173
173
  file->commit_data = data + chunk_commit_data->offset;
@@ -200,8 +200,7 @@ int git_commit_graph_file_parse(
200
200
  const unsigned char *chunk_hdr;
201
201
  struct git_commit_graph_chunk *last_chunk;
202
202
  uint32_t i;
203
- off64_t last_chunk_offset, chunk_offset, trailer_offset;
204
- unsigned char checksum[GIT_HASH_SHA1_SIZE];
203
+ uint64_t last_chunk_offset, chunk_offset, trailer_offset;
205
204
  size_t checksum_size;
206
205
  int error;
207
206
  struct git_commit_graph_chunk chunk_oid_fanout = {0}, chunk_oid_lookup = {0},
@@ -210,7 +209,7 @@ int git_commit_graph_file_parse(
210
209
 
211
210
  GIT_ASSERT_ARG(file);
212
211
 
213
- if (size < sizeof(struct git_commit_graph_header) + GIT_OID_RAWSZ)
212
+ if (size < sizeof(struct git_commit_graph_header) + GIT_OID_SHA1_SIZE)
214
213
  return commit_graph_error("commit-graph is too short");
215
214
 
216
215
  hdr = ((struct git_commit_graph_header *)data);
@@ -227,23 +226,18 @@ int git_commit_graph_file_parse(
227
226
  * headers, and a special zero chunk.
228
227
  */
229
228
  last_chunk_offset = sizeof(struct git_commit_graph_header) + (1 + hdr->chunks) * 12;
230
- trailer_offset = size - GIT_OID_RAWSZ;
229
+ trailer_offset = size - GIT_OID_SHA1_SIZE;
231
230
  checksum_size = GIT_HASH_SHA1_SIZE;
232
231
 
233
232
  if (trailer_offset < last_chunk_offset)
234
233
  return commit_graph_error("wrong commit-graph size");
235
234
  memcpy(file->checksum, (data + trailer_offset), checksum_size);
236
235
 
237
- if (git_hash_buf(checksum, data, (size_t)trailer_offset, GIT_HASH_ALGORITHM_SHA1) < 0)
238
- return commit_graph_error("could not calculate signature");
239
- if (memcmp(checksum, file->checksum, checksum_size) != 0)
240
- return commit_graph_error("index signature mismatch");
241
-
242
236
  chunk_hdr = data + sizeof(struct git_commit_graph_header);
243
237
  last_chunk = NULL;
244
238
  for (i = 0; i < hdr->chunks; ++i, chunk_hdr += 12) {
245
- chunk_offset = ((off64_t)ntohl(*((uint32_t *)(chunk_hdr + 4)))) << 32
246
- | ((off64_t)ntohl(*((uint32_t *)(chunk_hdr + 8))));
239
+ chunk_offset = ((uint64_t)ntohl(*((uint32_t *)(chunk_hdr + 4)))) << 32
240
+ | ((uint64_t)ntohl(*((uint32_t *)(chunk_hdr + 8))));
247
241
  if (chunk_offset < last_chunk_offset)
248
242
  return commit_graph_error("chunks are non-monotonic");
249
243
  if (chunk_offset >= trailer_offset)
@@ -331,9 +325,29 @@ error:
331
325
  return error;
332
326
  }
333
327
 
328
+ int git_commit_graph_validate(git_commit_graph *cgraph) {
329
+ unsigned char checksum[GIT_HASH_SHA1_SIZE];
330
+ size_t checksum_size = GIT_HASH_SHA1_SIZE;
331
+ size_t trailer_offset = cgraph->file->graph_map.len - checksum_size;
332
+
333
+ if (cgraph->file->graph_map.len < checksum_size)
334
+ return commit_graph_error("map length too small");
335
+
336
+ if (git_hash_buf(checksum, cgraph->file->graph_map.data, trailer_offset, GIT_HASH_ALGORITHM_SHA1) < 0)
337
+ return commit_graph_error("could not calculate signature");
338
+ if (memcmp(checksum, cgraph->file->checksum, checksum_size) != 0)
339
+ return commit_graph_error("index signature mismatch");
340
+
341
+ return 0;
342
+ }
343
+
334
344
  int git_commit_graph_open(git_commit_graph **cgraph_out, const char *objects_dir)
335
345
  {
336
- return git_commit_graph_new(cgraph_out, objects_dir, true);
346
+ int error = git_commit_graph_new(cgraph_out, objects_dir, true);
347
+ if (!error) {
348
+ return git_commit_graph_validate(*cgraph_out);
349
+ }
350
+ return error;
337
351
  }
338
352
 
339
353
  int git_commit_graph_file_open(git_commit_graph_file **file_out, const char *path)
@@ -436,15 +450,15 @@ static int git_commit_graph_entry_get_byindex(
436
450
  return GIT_ENOTFOUND;
437
451
  }
438
452
 
439
- commit_data = file->commit_data + pos * (GIT_OID_RAWSZ + 4 * sizeof(uint32_t));
440
- git_oid_fromraw(&e->tree_oid, commit_data);
441
- e->parent_indices[0] = ntohl(*((uint32_t *)(commit_data + GIT_OID_RAWSZ)));
453
+ commit_data = file->commit_data + pos * (GIT_OID_SHA1_SIZE + 4 * sizeof(uint32_t));
454
+ git_oid__fromraw(&e->tree_oid, commit_data, GIT_OID_SHA1);
455
+ e->parent_indices[0] = ntohl(*((uint32_t *)(commit_data + GIT_OID_SHA1_SIZE)));
442
456
  e->parent_indices[1] = ntohl(
443
- *((uint32_t *)(commit_data + GIT_OID_RAWSZ + sizeof(uint32_t))));
457
+ *((uint32_t *)(commit_data + GIT_OID_SHA1_SIZE + sizeof(uint32_t))));
444
458
  e->parent_count = (e->parent_indices[0] != GIT_COMMIT_GRAPH_MISSING_PARENT)
445
459
  + (e->parent_indices[1] != GIT_COMMIT_GRAPH_MISSING_PARENT);
446
- e->generation = ntohl(*((uint32_t *)(commit_data + GIT_OID_RAWSZ + 2 * sizeof(uint32_t))));
447
- e->commit_time = ntohl(*((uint32_t *)(commit_data + GIT_OID_RAWSZ + 3 * sizeof(uint32_t))));
460
+ e->generation = ntohl(*((uint32_t *)(commit_data + GIT_OID_SHA1_SIZE + 2 * sizeof(uint32_t))));
461
+ e->commit_time = ntohl(*((uint32_t *)(commit_data + GIT_OID_SHA1_SIZE + 3 * sizeof(uint32_t))));
448
462
 
449
463
  e->commit_time |= (e->generation & UINT64_C(0x3)) << UINT64_C(32);
450
464
  e->generation >>= 2u;
@@ -471,7 +485,7 @@ static int git_commit_graph_entry_get_byindex(
471
485
  }
472
486
  }
473
487
 
474
- git_oid_fromraw(&e->sha1, &file->oid_lookup[pos * GIT_OID_RAWSZ]);
488
+ git_oid__fromraw(&e->sha1, &file->oid_lookup[pos * GIT_OID_SHA1_SIZE], GIT_OID_SHA1);
475
489
  return 0;
476
490
  }
477
491
 
@@ -524,27 +538,27 @@ int git_commit_graph_entry_find(
524
538
  hi = ntohl(file->oid_fanout[(int)short_oid->id[0]]);
525
539
  lo = ((short_oid->id[0] == 0x0) ? 0 : ntohl(file->oid_fanout[(int)short_oid->id[0] - 1]));
526
540
 
527
- pos = git_pack__lookup_sha1(file->oid_lookup, GIT_OID_RAWSZ, lo, hi, short_oid->id);
541
+ pos = git_pack__lookup_id(file->oid_lookup, GIT_OID_SHA1_SIZE, lo, hi, short_oid->id, GIT_OID_SHA1);
528
542
 
529
543
  if (pos >= 0) {
530
544
  /* An object matching exactly the oid was found */
531
545
  found = 1;
532
- current = file->oid_lookup + (pos * GIT_OID_RAWSZ);
546
+ current = file->oid_lookup + (pos * GIT_OID_SHA1_SIZE);
533
547
  } else {
534
548
  /* No object was found */
535
549
  /* pos refers to the object with the "closest" oid to short_oid */
536
550
  pos = -1 - pos;
537
551
  if (pos < (int)file->num_commits) {
538
- current = file->oid_lookup + (pos * GIT_OID_RAWSZ);
552
+ current = file->oid_lookup + (pos * GIT_OID_SHA1_SIZE);
539
553
 
540
554
  if (!git_oid_raw_ncmp(short_oid->id, current, len))
541
555
  found = 1;
542
556
  }
543
557
  }
544
558
 
545
- if (found && len != GIT_OID_HEXSZ && pos + 1 < (int)file->num_commits) {
559
+ if (found && len != GIT_OID_SHA1_HEXSIZE && pos + 1 < (int)file->num_commits) {
546
560
  /* Check for ambiguousity */
547
- const unsigned char *next = current + GIT_OID_RAWSZ;
561
+ const unsigned char *next = current + GIT_OID_SHA1_SIZE;
548
562
 
549
563
  if (!git_oid_raw_ncmp(short_oid->id, next, len))
550
564
  found = 2;
@@ -712,7 +726,8 @@ int git_commit_graph_writer_add_index_file(
712
726
  if (error < 0)
713
727
  goto cleanup;
714
728
 
715
- error = git_mwindow_get_pack(&p, idx_path);
729
+ /* TODO: SHA256 */
730
+ error = git_mwindow_get_pack(&p, idx_path, 0);
716
731
  if (error < 0)
717
732
  goto cleanup;
718
733
 
@@ -1020,7 +1035,7 @@ static int commit_graph_write(
1020
1035
  git_vector_foreach (&w->commits, i, packed_commit) {
1021
1036
  error = git_str_put(&oid_lookup,
1022
1037
  (const char *)&packed_commit->sha1.id,
1023
- GIT_OID_RAWSZ);
1038
+ GIT_OID_SHA1_SIZE);
1024
1039
 
1025
1040
  if (error < 0)
1026
1041
  goto cleanup;
@@ -1037,7 +1052,7 @@ static int commit_graph_write(
1037
1052
 
1038
1053
  error = git_str_put(&commit_data,
1039
1054
  (const char *)&packed_commit->tree_oid.id,
1040
- GIT_OID_RAWSZ);
1055
+ GIT_OID_SHA1_SIZE);
1041
1056
 
1042
1057
  if (error < 0)
1043
1058
  goto cleanup;
@@ -106,6 +106,9 @@ struct git_commit_graph {
106
106
  /** Create a new commit-graph, optionally opening the underlying file. */
107
107
  int git_commit_graph_new(git_commit_graph **cgraph_out, const char *objects_dir, bool open_file);
108
108
 
109
+ /** Validate the checksum of a commit graph */
110
+ int git_commit_graph_validate(git_commit_graph *cgraph);
111
+
109
112
  /** Open and validate a commit-graph file. */
110
113
  int git_commit_graph_file_open(git_commit_graph_file **file_out, const char *path);
111
114
 
@@ -124,13 +124,17 @@ static int commit_quick_parse(
124
124
  {
125
125
  git_oid *parent_oid;
126
126
  git_commit *commit;
127
+ git_commit__parse_options parse_opts = {
128
+ GIT_OID_SHA1,
129
+ GIT_COMMIT_PARSE_QUICK
130
+ };
127
131
  size_t i;
128
132
 
129
133
  commit = git__calloc(1, sizeof(*commit));
130
134
  GIT_ERROR_CHECK_ALLOC(commit);
131
135
  commit->object.repo = walk->repo;
132
136
 
133
- if (git_commit__parse_ext(commit, obj, GIT_COMMIT_PARSE_QUICK) < 0) {
137
+ if (git_commit__parse_ext(commit, obj, &parse_opts) < 0) {
134
138
  git__free(commit);
135
139
  return -1;
136
140
  }
@@ -172,7 +176,7 @@ int git_commit_list_parse(git_revwalk *walk, git_commit_list_node *commit)
172
176
  if (cgraph_file) {
173
177
  git_commit_graph_entry e;
174
178
 
175
- error = git_commit_graph_entry_find(&e, cgraph_file, &commit->oid, GIT_OID_RAWSZ);
179
+ error = git_commit_graph_entry_find(&e, cgraph_file, &commit->oid, GIT_OID_SHA1_SIZE);
176
180
  if (error == 0 && git__is_uint16(e.parent_count)) {
177
181
  size_t i;
178
182
  commit->generation = (uint32_t)e.generation;
@@ -860,7 +860,7 @@ static int git_config__parse_path(git_str *out, const char *value)
860
860
  return -1;
861
861
  }
862
862
 
863
- return git_sysdir_expand_global_file(out, value[1] ? &value[2] : NULL);
863
+ return git_sysdir_expand_homedir_file(out, value[1] ? &value[2] : NULL);
864
864
  }
865
865
 
866
866
  return git_str_sets(out, value);
@@ -528,7 +528,7 @@ static int included_path(git_str *out, const char *dir, const char *path)
528
528
  {
529
529
  /* From the user's home */
530
530
  if (path[0] == '~' && path[1] == '/')
531
- return git_sysdir_expand_global_file(out, &path[1]);
531
+ return git_sysdir_expand_homedir_file(out, &path[1]);
532
532
 
533
533
  return git_fs_path_join_unrooted(out, path, dir, NULL);
534
534
  }
@@ -616,7 +616,7 @@ static int do_match_gitdir(
616
616
  git_fs_path_dirname_r(&pattern, cfg_file);
617
617
  git_str_joinpath(&pattern, pattern.ptr, condition + 2);
618
618
  } else if (condition[0] == '~' && git_fs_path_is_dirsep(condition[1]))
619
- git_sysdir_expand_global_file(&pattern, condition + 1);
619
+ git_sysdir_expand_homedir_file(&pattern, condition + 1);
620
620
  else if (!git_fs_path_is_absolute(condition))
621
621
  git_str_joinpath(&pattern, "**", condition);
622
622
  else
@@ -8,7 +8,6 @@
8
8
  #include "common.h"
9
9
 
10
10
  #include "git2/describe.h"
11
- #include "git2/strarray.h"
12
11
  #include "git2/diff.h"
13
12
  #include "git2/status.h"
14
13
 
@@ -19,6 +18,7 @@
19
18
  #include "refs.h"
20
19
  #include "repository.h"
21
20
  #include "revwalk.h"
21
+ #include "strarray.h"
22
22
  #include "tag.h"
23
23
  #include "vector.h"
24
24
  #include "wildmatch.h"
@@ -368,7 +368,7 @@ static int find_unique_abbrev_size(
368
368
  if ((error = git_repository_odb__weakptr(&odb, repo)) < 0)
369
369
  return error;
370
370
 
371
- while (size < GIT_OID_HEXSZ) {
371
+ while (size < GIT_OID_SHA1_HEXSIZE) {
372
372
  if ((error = git_odb_exists_prefix(&dummy, odb, oid_in, size)) == 0) {
373
373
  *out = (int) size;
374
374
  return 0;
@@ -383,7 +383,7 @@ static int find_unique_abbrev_size(
383
383
  }
384
384
 
385
385
  /* If we didn't find any shorter prefix, we have to do the whole thing */
386
- *out = GIT_OID_HEXSZ;
386
+ *out = GIT_OID_SHA1_HEXSIZE;
387
387
 
388
388
  return 0;
389
389
  }
@@ -397,7 +397,7 @@ static int show_suffix(
397
397
  {
398
398
  int error, size = 0;
399
399
 
400
- char hex_oid[GIT_OID_HEXSZ];
400
+ char hex_oid[GIT_OID_SHA1_HEXSIZE];
401
401
 
402
402
  if ((error = find_unique_abbrev_size(&size, repo, id, abbrev_size)) < 0)
403
403
  return error;
@@ -414,7 +414,7 @@ static int show_suffix(
414
414
  #define MAX_CANDIDATES_TAGS FLAG_BITS - 1
415
415
 
416
416
  static int describe_not_found(const git_oid *oid, const char *message_format) {
417
- char oid_str[GIT_OID_HEXSZ + 1];
417
+ char oid_str[GIT_OID_SHA1_HEXSIZE + 1];
418
418
  git_oid_tostr(oid_str, sizeof(oid_str), oid);
419
419
 
420
420
  git_error_set(GIT_ERROR_DESCRIBE, message_format, oid_str);
@@ -525,7 +525,7 @@ static int describe(
525
525
  if (annotated_cnt && (git_pqueue_size(&list) == 0)) {
526
526
  /*
527
527
  if (debug) {
528
- char oid_str[GIT_OID_HEXSZ + 1];
528
+ char oid_str[GIT_OID_SHA1_HEXSIZE + 1];
529
529
  git_oid_tostr(oid_str, sizeof(oid_str), &c->oid);
530
530
 
531
531
  fprintf(stderr, "finished search at %s\n", oid_str);
@@ -592,7 +592,7 @@ static int describe(
592
592
  "head", "lightweight", "annotated",
593
593
  };
594
594
 
595
- char oid_str[GIT_OID_HEXSZ + 1];
595
+ char oid_str[GIT_OID_SHA1_HEXSIZE + 1];
596
596
 
597
597
  if (debug) {
598
598
  for (cur_match = 0; cur_match < match_cnt; cur_match++) {
@@ -816,7 +816,7 @@ static int git_describe__format(
816
816
 
817
817
  /* If we didn't find *any* tags, we fall back to the commit's id */
818
818
  if (result->fallback_to_id) {
819
- char hex_oid[GIT_OID_HEXSZ + 1] = {0};
819
+ char hex_oid[GIT_OID_SHA1_HEXSIZE + 1] = {0};
820
820
  int size = 0;
821
821
 
822
822
  if ((error = find_unique_abbrev_size(
@@ -290,7 +290,7 @@ static int flush_hunk(git_oid *result, git_hash_ctx *ctx)
290
290
  (error = git_hash_init(ctx)) < 0)
291
291
  return error;
292
292
 
293
- for (i = 0; i < GIT_OID_RAWSZ; i++) {
293
+ for (i = 0; i < GIT_OID_SHA1_SIZE; i++) {
294
294
  carry += result->id[i] + hash.id[i];
295
295
  result->id[i] = (unsigned char)carry;
296
296
  carry >>= 8;
@@ -381,6 +381,10 @@ int git_diff_patchid(git_oid *out, git_diff *diff, git_diff_patchid_options *opt
381
381
  if ((error = (flush_hunk(&args.result, &args.ctx))) < 0)
382
382
  goto out;
383
383
 
384
+ #ifdef GIT_EXPERIMENTAL_SHA256
385
+ args.result.type = GIT_OID_SHA1;
386
+ #endif
387
+
384
388
  git_oid_cpy(out, &args.result);
385
389
 
386
390
  out:
@@ -144,6 +144,7 @@ int git_diff_file_content__init_from_src(
144
144
 
145
145
  if (!src->blob && !src->buf) {
146
146
  fc->flags |= GIT_DIFF_FLAG__NO_DATA;
147
+ git_oid_clear(&fc->file->id, GIT_OID_SHA1);
147
148
  } else {
148
149
  fc->flags |= GIT_DIFF_FLAG__LOADED;
149
150
  fc->file->flags |= GIT_DIFF_FLAG_VALID_ID;
@@ -153,7 +154,7 @@ int git_diff_file_content__init_from_src(
153
154
  git_blob_dup((git_blob **)&fc->blob, (git_blob *) src->blob);
154
155
  fc->file->size = git_blob_rawsize(src->blob);
155
156
  git_oid_cpy(&fc->file->id, git_blob_id(src->blob));
156
- fc->file->id_abbrev = GIT_OID_HEXSZ;
157
+ fc->file->id_abbrev = GIT_OID_SHA1_HEXSIZE;
157
158
 
158
159
  fc->map.len = (size_t)fc->file->size;
159
160
  fc->map.data = (char *)git_blob_rawcontent(src->blob);
@@ -161,10 +162,10 @@ int git_diff_file_content__init_from_src(
161
162
  fc->flags |= GIT_DIFF_FLAG__FREE_BLOB;
162
163
  } else {
163
164
  int error;
164
- if ((error = git_odb_hash(&fc->file->id, src->buf, src->buflen, GIT_OBJECT_BLOB)) < 0)
165
+ if ((error = git_odb__hash(&fc->file->id, src->buf, src->buflen, GIT_OBJECT_BLOB, GIT_OID_SHA1)) < 0)
165
166
  return error;
166
167
  fc->file->size = src->buflen;
167
- fc->file->id_abbrev = GIT_OID_HEXSZ;
168
+ fc->file->id_abbrev = GIT_OID_SHA1_HEXSIZE;
168
169
 
169
170
  fc->map.len = src->buflen;
170
171
  fc->map.data = (char *)src->buf;
@@ -177,7 +178,7 @@ int git_diff_file_content__init_from_src(
177
178
  static int diff_file_content_commit_to_str(
178
179
  git_diff_file_content *fc, bool check_status)
179
180
  {
180
- char oid[GIT_OID_HEXSZ+1];
181
+ char oid[GIT_OID_SHA1_HEXSIZE+1];
181
182
  git_str content = GIT_STR_INIT;
182
183
  const char *status = "";
183
184
 
@@ -347,6 +348,13 @@ static int diff_file_content_load_workdir_file(
347
348
  goto cleanup;
348
349
  }
349
350
 
351
+ /* if file is empty, don't attempt to mmap or readbuffer */
352
+ if (fc->file->size == 0) {
353
+ fc->map.len = 0;
354
+ fc->map.data = git_str__initstr;
355
+ goto cleanup;
356
+ }
357
+
350
358
  if ((diff_opts->flags & GIT_DIFF_SHOW_BINARY) == 0 &&
351
359
  diff_file_content_binary_by_size(fc))
352
360
  goto cleanup;
@@ -410,8 +418,9 @@ static int diff_file_content_load_workdir(
410
418
 
411
419
  /* once data is loaded, update OID if we didn't have it previously */
412
420
  if (!error && (fc->file->flags & GIT_DIFF_FLAG_VALID_ID) == 0) {
413
- error = git_odb_hash(
414
- &fc->file->id, fc->map.data, fc->map.len, GIT_OBJECT_BLOB);
421
+ error = git_odb__hash(
422
+ &fc->file->id, fc->map.data, fc->map.len,
423
+ GIT_OBJECT_BLOB, GIT_OID_SHA1);
415
424
  fc->file->flags |= GIT_DIFF_FLAG_VALID_ID;
416
425
  }
417
426
 
@@ -61,6 +61,9 @@ static git_diff_delta *diff_delta__alloc(
61
61
  }
62
62
  delta->status = status;
63
63
 
64
+ git_oid_clear(&delta->old_file.id, GIT_OID_SHA1);
65
+ git_oid_clear(&delta->new_file.id, GIT_OID_SHA1);
66
+
64
67
  return delta;
65
68
  }
66
69
 
@@ -188,13 +191,15 @@ static int diff_delta__from_one(
188
191
  delta->old_file.size = entry->file_size;
189
192
  delta->old_file.flags |= GIT_DIFF_FLAG_EXISTS;
190
193
  git_oid_cpy(&delta->old_file.id, &entry->id);
191
- delta->old_file.id_abbrev = GIT_OID_HEXSZ;
194
+ git_oid_clear(&delta->new_file.id, GIT_OID_SHA1);
195
+ delta->old_file.id_abbrev = GIT_OID_SHA1_HEXSIZE;
192
196
  } else /* ADDED, IGNORED, UNTRACKED */ {
193
197
  delta->new_file.mode = entry->mode;
194
198
  delta->new_file.size = entry->file_size;
195
199
  delta->new_file.flags |= GIT_DIFF_FLAG_EXISTS;
200
+ git_oid_clear(&delta->old_file.id, GIT_OID_SHA1);
196
201
  git_oid_cpy(&delta->new_file.id, &entry->id);
197
- delta->new_file.id_abbrev = GIT_OID_HEXSZ;
202
+ delta->new_file.id_abbrev = GIT_OID_SHA1_HEXSIZE;
198
203
  }
199
204
 
200
205
  delta->old_file.flags |= GIT_DIFF_FLAG_VALID_ID;
@@ -249,14 +254,14 @@ static int diff_delta__from_two(
249
254
  delta->old_file.size = old_entry->file_size;
250
255
  delta->old_file.mode = old_mode;
251
256
  git_oid_cpy(&delta->old_file.id, old_id);
252
- delta->old_file.id_abbrev = GIT_OID_HEXSZ;
257
+ delta->old_file.id_abbrev = GIT_OID_SHA1_HEXSIZE;
253
258
  delta->old_file.flags |= GIT_DIFF_FLAG_VALID_ID |
254
259
  GIT_DIFF_FLAG_EXISTS;
255
260
  }
256
261
 
257
262
  if (!git_index_entry_is_conflict(new_entry)) {
258
263
  git_oid_cpy(&delta->new_file.id, new_id);
259
- delta->new_file.id_abbrev = GIT_OID_HEXSZ;
264
+ delta->new_file.id_abbrev = GIT_OID_SHA1_HEXSIZE;
260
265
  delta->new_file.size = new_entry->file_size;
261
266
  delta->new_file.mode = new_mode;
262
267
  delta->old_file.flags |= GIT_DIFF_FLAG_EXISTS;
@@ -598,6 +603,7 @@ int git_diff__oid_for_file(
598
603
  entry.mode = mode;
599
604
  entry.file_size = (uint32_t)size;
600
605
  entry.path = (char *)path;
606
+ git_oid_clear(&entry.id, GIT_OID_SHA1);
601
607
 
602
608
  return git_diff__oid_for_entry(out, diff, &entry, mode, NULL);
603
609
  }
@@ -618,7 +624,7 @@ int git_diff__oid_for_entry(
618
624
  GIT_ASSERT(d->type == GIT_DIFF_TYPE_GENERATED);
619
625
  diff = (git_diff_generated *)d;
620
626
 
621
- memset(out, 0, sizeof(*out));
627
+ git_oid_clear(out, GIT_OID_SHA1);
622
628
 
623
629
  if (git_repository_workdir_path(&full_path, diff->base.repo, entry.path) < 0)
624
630
  return -1;
@@ -654,7 +660,7 @@ int git_diff__oid_for_entry(
654
660
  git_error_clear();
655
661
  }
656
662
  } else if (S_ISLNK(mode)) {
657
- error = git_odb__hashlink(out, full_path.ptr);
663
+ error = git_odb__hashlink(out, full_path.ptr, GIT_OID_SHA1);
658
664
  diff->base.perf.oid_calculations++;
659
665
  } else if (!git__is_sizet(entry.file_size)) {
660
666
  git_error_set(GIT_ERROR_NOMEMORY, "file size overflow (for 32-bits) on '%s'",
@@ -669,7 +675,8 @@ int git_diff__oid_for_entry(
669
675
  error = fd;
670
676
  else {
671
677
  error = git_odb__hashfd_filtered(
672
- out, fd, (size_t)entry.file_size, GIT_OBJECT_BLOB, fl);
678
+ out, fd, (size_t)entry.file_size,
679
+ GIT_OBJECT_BLOB, GIT_OID_SHA1, fl);
673
680
  p_close(fd);
674
681
  diff->base.perf.oid_calculations++;
675
682
  }
@@ -778,7 +785,7 @@ static int maybe_modified(
778
785
  git_diff_generated *diff,
779
786
  diff_in_progress *info)
780
787
  {
781
- git_oid noid;
788
+ git_oid noid = GIT_OID_SHA1_ZERO;
782
789
  git_delta_t status = GIT_DELTA_MODIFIED;
783
790
  const git_index_entry *oitem = info->oitem;
784
791
  const git_index_entry *nitem = info->nitem;
@@ -792,8 +799,6 @@ static int maybe_modified(
792
799
  if (!diff_pathspec_match(&matched_pathspec, diff, oitem))
793
800
  return 0;
794
801
 
795
- memset(&noid, 0, sizeof(noid));
796
-
797
802
  /* on platforms with no symlinks, preserve mode of existing symlinks */
798
803
  if (S_ISLNK(omode) && S_ISREG(nmode) && new_is_workdir &&
799
804
  !(diff->diffcaps & GIT_DIFFCAPS_HAS_SYMLINKS))
@@ -1695,11 +1700,11 @@ int git_diff__commit(
1695
1700
  *out = NULL;
1696
1701
 
1697
1702
  if ((parents = git_commit_parentcount(commit)) > 1) {
1698
- char commit_oidstr[GIT_OID_HEXSZ + 1];
1703
+ char commit_oidstr[GIT_OID_SHA1_HEXSIZE + 1];
1699
1704
 
1700
1705
  error = -1;
1701
1706
  git_error_set(GIT_ERROR_INVALID, "commit %s is a merge commit",
1702
- git_oid_tostr(commit_oidstr, GIT_OID_HEXSZ + 1, git_commit_id(commit)));
1707
+ git_oid_tostr(commit_oidstr, GIT_OID_SHA1_HEXSIZE + 1, git_commit_id(commit)));
1703
1708
  goto on_error;
1704
1709
  }
1705
1710
 
@@ -53,8 +53,8 @@ static int diff_print_info_init__common(
53
53
  return -1;
54
54
  }
55
55
 
56
- if (pi->id_strlen > GIT_OID_HEXSZ)
57
- pi->id_strlen = GIT_OID_HEXSZ;
56
+ if (pi->id_strlen > GIT_OID_SHA1_HEXSIZE)
57
+ pi->id_strlen = GIT_OID_SHA1_HEXSIZE;
58
58
 
59
59
  memset(&pi->line, 0, sizeof(pi->line));
60
60
  pi->line.old_lineno = -1;
@@ -212,7 +212,7 @@ static int diff_print_one_raw(
212
212
  git_str *out = pi->buf;
213
213
  int id_abbrev;
214
214
  char code = git_diff_status_char(delta->status);
215
- char start_oid[GIT_OID_HEXSZ+1], end_oid[GIT_OID_HEXSZ+1];
215
+ char start_oid[GIT_OID_SHA1_HEXSIZE+1], end_oid[GIT_OID_SHA1_HEXSIZE+1];
216
216
 
217
217
  GIT_UNUSED(progress);
218
218
 
@@ -235,7 +235,7 @@ static int diff_print_one_raw(
235
235
  git_oid_tostr(end_oid, pi->id_strlen + 1, &delta->new_file.id);
236
236
 
237
237
  git_str_printf(
238
- out, (pi->id_strlen <= GIT_OID_HEXSZ) ?
238
+ out, (pi->id_strlen <= GIT_OID_SHA1_HEXSIZE) ?
239
239
  ":%06o %06o %s... %s... %c" : ":%06o %06o %s %s %c",
240
240
  delta->old_file.mode, delta->new_file.mode, start_oid, end_oid, code);
241
241
 
@@ -273,7 +273,7 @@ static int diff_print_oid_range(
273
273
  git_str *out, const git_diff_delta *delta, int id_strlen,
274
274
  bool print_index)
275
275
  {
276
- char start_oid[GIT_OID_HEXSZ+1], end_oid[GIT_OID_HEXSZ+1];
276
+ char start_oid[GIT_OID_SHA1_HEXSIZE+1], end_oid[GIT_OID_SHA1_HEXSIZE+1];
277
277
 
278
278
  if (delta->old_file.mode &&
279
279
  id_strlen > delta->old_file.id_abbrev) {
@@ -364,6 +364,7 @@ static int insert_delete_side_of_split(
364
364
  memset(&deleted->new_file, 0, sizeof(deleted->new_file));
365
365
  deleted->new_file.path = deleted->old_file.path;
366
366
  deleted->new_file.flags |= GIT_DIFF_FLAG_VALID_ID;
367
+ git_oid_clear(&deleted->new_file.id, GIT_OID_SHA1);
367
368
 
368
369
  return git_vector_insert(onto, deleted);
369
370
  }
@@ -397,6 +398,7 @@ static int apply_splits_and_deletes(
397
398
  memset(&delta->old_file, 0, sizeof(delta->old_file));
398
399
  delta->old_file.path = delta->new_file.path;
399
400
  delta->old_file.flags |= GIT_DIFF_FLAG_VALID_ID;
401
+ git_oid_clear(&delta->old_file.id, GIT_OID_SHA1);
400
402
  }
401
403
 
402
404
  /* clean up delta before inserting into new list */
@@ -995,6 +997,7 @@ find_best_matches:
995
997
  memset(&src->new_file, 0, sizeof(src->new_file));
996
998
  src->new_file.path = src->old_file.path;
997
999
  src->new_file.flags |= GIT_DIFF_FLAG_VALID_ID;
1000
+ git_oid_clear(&src->new_file.id, GIT_OID_SHA1);
998
1001
 
999
1002
  num_updates++;
1000
1003
 
@@ -1020,6 +1023,7 @@ find_best_matches:
1020
1023
  memset(&src->old_file, 0, sizeof(src->old_file));
1021
1024
  src->old_file.path = src->new_file.path;
1022
1025
  src->old_file.flags |= GIT_DIFF_FLAG_VALID_ID;
1026
+ git_oid_clear(&src->old_file.id, GIT_OID_SHA1);
1023
1027
 
1024
1028
  src->flags &= ~GIT_DIFF_FLAG__TO_SPLIT;
1025
1029
  num_rewrites--;
@@ -130,11 +130,11 @@ static int append_header(
130
130
  const git_signature *author,
131
131
  git_email_create_options *opts)
132
132
  {
133
- char id[GIT_OID_HEXSZ];
133
+ char id[GIT_OID_SHA1_HEXSIZE];
134
134
  int error;
135
135
 
136
136
  if ((error = git_oid_fmt(id, commit_id)) < 0 ||
137
- (error = git_str_printf(out, "From %.*s %s\n", GIT_OID_HEXSZ, id, EMAIL_TIMESTAMP)) < 0 ||
137
+ (error = git_str_printf(out, "From %.*s %s\n", GIT_OID_SHA1_HEXSIZE, id, EMAIL_TIMESTAMP)) < 0 ||
138
138
  (error = git_str_printf(out, "From: %s <%s>\n", author->name, author->email)) < 0 ||
139
139
  (error = append_date(out, &author->when)) < 0 ||
140
140
  (error = append_subject(out, patch_idx, patch_count, summary, opts)) < 0)
@@ -0,0 +1,13 @@
1
+ /*
2
+ * Copyright (C) the libgit2 contributors. All rights reserved.
3
+ *
4
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
5
+ * a Linking Exception. For full terms see the included COPYING file.
6
+ */
7
+
8
+ #ifndef INCLUDE_experimental_h__
9
+ #define INCLUDE_experimental_h__
10
+
11
+ #cmakedefine GIT_EXPERIMENTAL_SHA256 1
12
+
13
+ #endif