rugged 1.5.1 → 1.6.3

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 +5 -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 +24 -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 +13 -12
  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 +213 -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 +92 -69
  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 +41 -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 +6 -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
@@ -115,19 +115,19 @@ static int midx_parse_oid_lookup(
115
115
  struct git_midx_chunk *chunk_oid_lookup)
116
116
  {
117
117
  uint32_t i;
118
- unsigned char *oid, *prev_oid, zero_oid[GIT_OID_RAWSZ] = {0};
118
+ unsigned char *oid, *prev_oid, zero_oid[GIT_OID_SHA1_SIZE] = {0};
119
119
 
120
120
  if (chunk_oid_lookup->offset == 0)
121
121
  return midx_error("missing OID Lookup chunk");
122
122
  if (chunk_oid_lookup->length == 0)
123
123
  return midx_error("empty OID Lookup chunk");
124
- if (chunk_oid_lookup->length != idx->num_objects * GIT_OID_RAWSZ)
124
+ if (chunk_oid_lookup->length != idx->num_objects * GIT_OID_SHA1_SIZE)
125
125
  return midx_error("OID Lookup chunk has wrong length");
126
126
 
127
127
  idx->oid_lookup = oid = (unsigned char *)(data + chunk_oid_lookup->offset);
128
128
  prev_oid = zero_oid;
129
- for (i = 0; i < idx->num_objects; ++i, oid += GIT_OID_RAWSZ) {
130
- if (git_oid_raw_cmp(prev_oid, oid) >= 0)
129
+ for (i = 0; i < idx->num_objects; ++i, oid += GIT_OID_SHA1_SIZE) {
130
+ if (git_oid_raw_cmp(prev_oid, oid, GIT_OID_SHA1_SIZE) >= 0)
131
131
  return midx_error("OID Lookup index is non-monotonic");
132
132
  prev_oid = oid;
133
133
  }
@@ -188,7 +188,7 @@ int git_midx_parse(
188
188
 
189
189
  GIT_ASSERT_ARG(idx);
190
190
 
191
- if (size < sizeof(struct git_midx_header) + GIT_OID_RAWSZ)
191
+ if (size < sizeof(struct git_midx_header) + GIT_OID_SHA1_SIZE)
192
192
  return midx_error("multi-pack index is too short");
193
193
 
194
194
  hdr = ((struct git_midx_header *)data);
@@ -365,7 +365,7 @@ bool git_midx_needs_refresh(
365
365
  }
366
366
 
367
367
  checksum_size = GIT_HASH_SHA1_SIZE;
368
- bytes_read = p_pread(fd, checksum, checksum_size, st.st_size - GIT_OID_RAWSZ);
368
+ bytes_read = p_pread(fd, checksum, checksum_size, st.st_size - GIT_OID_SHA1_SIZE);
369
369
  p_close(fd);
370
370
 
371
371
  if (bytes_read != (ssize_t)checksum_size)
@@ -392,27 +392,27 @@ int git_midx_entry_find(
392
392
  hi = ntohl(idx->oid_fanout[(int)short_oid->id[0]]);
393
393
  lo = ((short_oid->id[0] == 0x0) ? 0 : ntohl(idx->oid_fanout[(int)short_oid->id[0] - 1]));
394
394
 
395
- pos = git_pack__lookup_sha1(idx->oid_lookup, GIT_OID_RAWSZ, lo, hi, short_oid->id);
395
+ pos = git_pack__lookup_id(idx->oid_lookup, GIT_OID_SHA1_SIZE, lo, hi, short_oid->id, GIT_OID_SHA1);
396
396
 
397
397
  if (pos >= 0) {
398
398
  /* An object matching exactly the oid was found */
399
399
  found = 1;
400
- current = idx->oid_lookup + (pos * GIT_OID_RAWSZ);
400
+ current = idx->oid_lookup + (pos * GIT_OID_SHA1_SIZE);
401
401
  } else {
402
402
  /* No object was found */
403
403
  /* pos refers to the object with the "closest" oid to short_oid */
404
404
  pos = -1 - pos;
405
405
  if (pos < (int)idx->num_objects) {
406
- current = idx->oid_lookup + (pos * GIT_OID_RAWSZ);
406
+ current = idx->oid_lookup + (pos * GIT_OID_SHA1_SIZE);
407
407
 
408
408
  if (!git_oid_raw_ncmp(short_oid->id, current, len))
409
409
  found = 1;
410
410
  }
411
411
  }
412
412
 
413
- if (found && len != GIT_OID_HEXSZ && pos + 1 < (int)idx->num_objects) {
413
+ if (found && len != GIT_OID_SHA1_HEXSIZE && pos + 1 < (int)idx->num_objects) {
414
414
  /* Check for ambiguousity */
415
- const unsigned char *next = current + GIT_OID_RAWSZ;
415
+ const unsigned char *next = current + GIT_OID_SHA1_SIZE;
416
416
 
417
417
  if (!git_oid_raw_ncmp(short_oid->id, next, len))
418
418
  found = 2;
@@ -443,7 +443,7 @@ int git_midx_entry_find(
443
443
  return midx_error("invalid index into the packfile names table");
444
444
  e->pack_index = pack_index;
445
445
  e->offset = offset;
446
- git_oid_fromraw(&e->sha1, current);
446
+ git_oid__fromraw(&e->sha1, current, GIT_OID_SHA1);
447
447
  return 0;
448
448
  }
449
449
 
@@ -459,7 +459,7 @@ int git_midx_foreach_entry(
459
459
  GIT_ASSERT_ARG(idx);
460
460
 
461
461
  for (i = 0; i < idx->num_objects; ++i) {
462
- if ((error = git_oid_fromraw(&oid, &idx->oid_lookup[i * GIT_OID_RAWSZ])) < 0)
462
+ if ((error = git_oid__fromraw(&oid, &idx->oid_lookup[i * GIT_OID_SHA1_SIZE], GIT_OID_SHA1)) < 0)
463
463
  return error;
464
464
 
465
465
  if ((error = cb(&oid, data)) != 0)
@@ -549,7 +549,8 @@ int git_midx_writer_add(
549
549
  if (error < 0)
550
550
  return error;
551
551
 
552
- error = git_mwindow_get_pack(&p, git_str_cstr(&idx_path_buf));
552
+ /* TODO: SHA256 */
553
+ error = git_mwindow_get_pack(&p, git_str_cstr(&idx_path_buf), 0);
553
554
  git_str_dispose(&idx_path_buf);
554
555
  if (error < 0)
555
556
  return error;
@@ -748,7 +749,7 @@ static int midx_write(
748
749
 
749
750
  /* Fill the OID Lookup table. */
750
751
  git_vector_foreach (&object_entries, i, entry) {
751
- error = git_str_put(&oid_lookup, (char *)&entry->sha1.id, GIT_OID_RAWSZ);
752
+ error = git_str_put(&oid_lookup, (char *)&entry->sha1.id, GIT_OID_SHA1_SIZE);
752
753
  if (error < 0)
753
754
  goto cleanup;
754
755
  }
@@ -61,7 +61,10 @@ int git_mwindow_global_init(void)
61
61
  return git_runtime_shutdown_register(git_mwindow_global_shutdown);
62
62
  }
63
63
 
64
- int git_mwindow_get_pack(struct git_pack_file **out, const char *path)
64
+ int git_mwindow_get_pack(
65
+ struct git_pack_file **out,
66
+ const char *path,
67
+ git_oid_t oid_type)
65
68
  {
66
69
  struct git_pack_file *pack;
67
70
  char *packname;
@@ -86,7 +89,7 @@ int git_mwindow_get_pack(struct git_pack_file **out, const char *path)
86
89
  }
87
90
 
88
91
  /* If we didn't find it, we need to create it */
89
- if ((error = git_packfile_alloc(&pack, path)) < 0) {
92
+ if ((error = git_packfile_alloc(&pack, path, oid_type)) < 0) {
90
93
  git_mutex_unlock(&git__mwindow_mutex);
91
94
  return error;
92
95
  }
@@ -48,7 +48,10 @@ void git_mwindow_close(git_mwindow **w_cursor);
48
48
  extern int git_mwindow_global_init(void);
49
49
 
50
50
  struct git_pack_file; /* just declaration to avoid cyclical includes */
51
- int git_mwindow_get_pack(struct git_pack_file **out, const char *path);
51
+ int git_mwindow_get_pack(
52
+ struct git_pack_file **out,
53
+ const char *path,
54
+ git_oid_t oid_type);
52
55
  int git_mwindow_put_pack(struct git_pack_file *pack);
53
56
 
54
57
  #endif
@@ -460,7 +460,7 @@ int git_note_commit_read(
460
460
  {
461
461
  int error;
462
462
  git_tree *tree = NULL;
463
- char target[GIT_OID_HEXSZ + 1];
463
+ char target[GIT_OID_SHA1_HEXSIZE + 1];
464
464
 
465
465
  git_oid_tostr(target, sizeof(target), oid);
466
466
 
@@ -507,7 +507,7 @@ int git_note_commit_create(
507
507
  {
508
508
  int error;
509
509
  git_tree *tree = NULL;
510
- char target[GIT_OID_HEXSZ + 1];
510
+ char target[GIT_OID_SHA1_HEXSIZE + 1];
511
511
 
512
512
  git_oid_tostr(target, sizeof(target), oid);
513
513
 
@@ -578,7 +578,7 @@ int git_note_commit_remove(
578
578
  {
579
579
  int error;
580
580
  git_tree *tree = NULL;
581
- char target[GIT_OID_HEXSZ + 1];
581
+ char target[GIT_OID_SHA1_HEXSIZE + 1];
582
582
 
583
583
  git_oid_tostr(target, sizeof(target), oid);
584
584
 
@@ -698,12 +698,12 @@ static int process_entry_path(
698
698
  buf.ptr[j] = '\0';
699
699
  buf.size = j;
700
700
 
701
- if (j != GIT_OID_HEXSZ) {
701
+ if (j != GIT_OID_SHA1_HEXSIZE) {
702
702
  /* This is not a note entry */
703
703
  goto cleanup;
704
704
  }
705
705
 
706
- error = git_oid_fromstr(annotated_object_id, buf.ptr);
706
+ error = git_oid__fromstr(annotated_object_id, buf.ptr, GIT_OID_SHA1);
707
707
 
708
708
  cleanup:
709
709
  git_str_dispose(&buf);
@@ -21,15 +21,14 @@
21
21
 
22
22
  bool git_object__strict_input_validation = true;
23
23
 
24
- extern int git_odb_hash(git_oid *out, const void *data, size_t len, git_object_t type);
25
24
  size_t git_object__size(git_object_t type);
26
25
 
27
26
  typedef struct {
28
27
  const char *str; /* type name string */
29
28
  size_t size; /* size in bytes of the object structure */
30
29
 
31
- int (*parse)(void *self, git_odb_object *obj);
32
- int (*parse_raw)(void *self, const char *data, size_t size);
30
+ int (*parse)(void *self, git_odb_object *obj, git_oid_t oid_type);
31
+ int (*parse_raw)(void *self, const char *data, size_t size, git_oid_t oid_type);
33
32
  void (*free)(void *self);
34
33
  } git_object_def;
35
34
 
@@ -61,7 +60,8 @@ int git_object__from_raw(
61
60
  git_object **object_out,
62
61
  const char *data,
63
62
  size_t size,
64
- git_object_t type)
63
+ git_object_t object_type,
64
+ git_oid_t oid_type)
65
65
  {
66
66
  git_object_def *def;
67
67
  git_object *object;
@@ -72,12 +72,15 @@ int git_object__from_raw(
72
72
  *object_out = NULL;
73
73
 
74
74
  /* Validate type match */
75
- if (type != GIT_OBJECT_BLOB && type != GIT_OBJECT_TREE && type != GIT_OBJECT_COMMIT && type != GIT_OBJECT_TAG) {
75
+ if (object_type != GIT_OBJECT_BLOB &&
76
+ object_type != GIT_OBJECT_TREE &&
77
+ object_type != GIT_OBJECT_COMMIT &&
78
+ object_type != GIT_OBJECT_TAG) {
76
79
  git_error_set(GIT_ERROR_INVALID, "the requested type is invalid");
77
80
  return GIT_ENOTFOUND;
78
81
  }
79
82
 
80
- if ((object_size = git_object__size(type)) == 0) {
83
+ if ((object_size = git_object__size(object_type)) == 0) {
81
84
  git_error_set(GIT_ERROR_INVALID, "the requested type is invalid");
82
85
  return GIT_ENOTFOUND;
83
86
  }
@@ -86,15 +89,15 @@ int git_object__from_raw(
86
89
  object = git__calloc(1, object_size);
87
90
  GIT_ERROR_CHECK_ALLOC(object);
88
91
  object->cached.flags = GIT_CACHE_STORE_PARSED;
89
- object->cached.type = type;
90
- if ((error = git_odb_hash(&object->cached.oid, data, size, type)) < 0)
92
+ object->cached.type = object_type;
93
+ if ((error = git_odb__hash(&object->cached.oid, data, size, object_type, oid_type)) < 0)
91
94
  return error;
92
95
 
93
96
  /* Parse raw object data */
94
- def = &git_objects_table[type];
97
+ def = &git_objects_table[object_type];
95
98
  GIT_ASSERT(def->free && def->parse_raw);
96
99
 
97
- if ((error = def->parse_raw(object, data, size)) < 0) {
100
+ if ((error = def->parse_raw(object, data, size, oid_type)) < 0) {
98
101
  def->free(object);
99
102
  return error;
100
103
  }
@@ -144,7 +147,7 @@ int git_object__from_odb_object(
144
147
  def = &git_objects_table[odb_obj->cached.type];
145
148
  GIT_ASSERT(def->free && def->parse);
146
149
 
147
- if ((error = def->parse(object, odb_obj)) < 0) {
150
+ if ((error = def->parse(object, odb_obj, repo->oid_type)) < 0) {
148
151
  /*
149
152
  * parse returns EINVALID on invalid data; downgrade
150
153
  * that to a normal -1 error code.
@@ -193,10 +196,10 @@ int git_object_lookup_prefix(
193
196
  if (error < 0)
194
197
  return error;
195
198
 
196
- if (len > GIT_OID_HEXSZ)
197
- len = GIT_OID_HEXSZ;
199
+ if (len > GIT_OID_SHA1_HEXSIZE)
200
+ len = GIT_OID_SHA1_HEXSIZE;
198
201
 
199
- if (len == GIT_OID_HEXSZ) {
202
+ if (len == GIT_OID_SHA1_HEXSIZE) {
200
203
  git_cached_obj *cached = NULL;
201
204
 
202
205
  /* We want to match the full id : we can first look up in the cache,
@@ -230,11 +233,11 @@ int git_object_lookup_prefix(
230
233
  error = git_odb_read(&odb_obj, odb, id);
231
234
  }
232
235
  } else {
233
- git_oid short_oid = {{ 0 }};
236
+ git_oid short_oid = GIT_OID_SHA1_ZERO;
234
237
 
235
238
  git_oid__cpy_prefix(&short_oid, id, len);
236
239
 
237
- /* If len < GIT_OID_HEXSZ (a strict short oid was given), we have
240
+ /* If len < GIT_OID_SHA1_HEXSIZE (a strict short oid was given), we have
238
241
  * 2 options :
239
242
  * - We always search in the cache first. If we find that short oid is
240
243
  * ambiguous, we can stop. But in all the other cases, we must then
@@ -259,7 +262,7 @@ int git_object_lookup_prefix(
259
262
  }
260
263
 
261
264
  int git_object_lookup(git_object **object_out, git_repository *repo, const git_oid *id, git_object_t type) {
262
- return git_object_lookup_prefix(object_out, repo, id, GIT_OID_HEXSZ, type);
265
+ return git_object_lookup_prefix(object_out, repo, id, GIT_OID_SHA1_HEXSIZE, type);
263
266
  }
264
267
 
265
268
  void git_object_free(git_object *object)
@@ -358,12 +361,11 @@ static int dereference_object(git_object **dereferenced, git_object *obj)
358
361
  static int peel_error(int error, const git_oid *oid, git_object_t type)
359
362
  {
360
363
  const char *type_name;
361
- char hex_oid[GIT_OID_HEXSZ + 1];
364
+ char hex_oid[GIT_OID_MAX_HEXSIZE + 1];
362
365
 
363
366
  type_name = git_object_type2string(type);
364
367
 
365
- git_oid_fmt(hex_oid, oid);
366
- hex_oid[GIT_OID_HEXSZ] = '\0';
368
+ git_oid_nfmt(hex_oid, GIT_OID_MAX_HEXSIZE + 1, oid);
367
369
 
368
370
  git_error_set(GIT_ERROR_OBJECT, "the git_object of id '%s' can not be "
369
371
  "successfully peeled into a %s (git_object_t=%i).", hex_oid, type_name, type);
@@ -502,7 +504,7 @@ static int git_object__short_id(git_str *out, const git_object *obj)
502
504
  {
503
505
  git_repository *repo;
504
506
  int len = GIT_ABBREV_DEFAULT, error;
505
- git_oid id = {{0}};
507
+ git_oid id = GIT_OID_SHA1_ZERO;
506
508
  git_odb *odb;
507
509
 
508
510
  GIT_ASSERT_ARG(out);
@@ -516,12 +518,16 @@ static int git_object__short_id(git_str *out, const git_object *obj)
516
518
  if ((error = git_repository_odb(&odb, repo)) < 0)
517
519
  return error;
518
520
 
519
- while (len < GIT_OID_HEXSZ) {
521
+ while (len < GIT_OID_SHA1_HEXSIZE) {
520
522
  /* set up short oid */
521
523
  memcpy(&id.id, &obj->cached.oid.id, (len + 1) / 2);
522
524
  if (len & 1)
523
525
  id.id[len / 2] &= 0xf0;
524
526
 
527
+ #ifdef GIT_EXPERIMENTAL_SHA256
528
+ id.type = GIT_OID_SHA1;
529
+ #endif
530
+
525
531
  error = git_odb_exists_prefix(NULL, odb, &id, len);
526
532
  if (error != GIT_EAMBIGUOUS)
527
533
  break;
@@ -573,21 +579,29 @@ int git_object_rawcontent_is_valid(
573
579
  int *valid,
574
580
  const char *buf,
575
581
  size_t len,
576
- git_object_t type)
582
+ git_object_t object_type
583
+ #ifdef GIT_EXPERIMENTAL_SHA256
584
+ , git_oid_t oid_type
585
+ #endif
586
+ )
577
587
  {
578
588
  git_object *obj = NULL;
579
589
  int error;
580
590
 
591
+ #ifndef GIT_EXPERIMENTAL_SHA256
592
+ git_oid_t oid_type = GIT_OID_SHA1;
593
+ #endif
594
+
581
595
  GIT_ASSERT_ARG(valid);
582
596
  GIT_ASSERT_ARG(buf);
583
597
 
584
598
  /* Blobs are always valid; don't bother parsing. */
585
- if (type == GIT_OBJECT_BLOB) {
599
+ if (object_type == GIT_OBJECT_BLOB) {
586
600
  *valid = 1;
587
601
  return 0;
588
602
  }
589
603
 
590
- error = git_object__from_raw(&obj, buf, len, type);
604
+ error = git_object__from_raw(&obj, buf, len, object_type, oid_type);
591
605
  git_object_free(obj);
592
606
 
593
607
  if (error == 0) {
@@ -600,3 +614,53 @@ int git_object_rawcontent_is_valid(
600
614
 
601
615
  return error;
602
616
  }
617
+
618
+ int git_object__parse_oid_header(
619
+ git_oid *oid,
620
+ const char **buffer_out,
621
+ const char *buffer_end,
622
+ const char *header,
623
+ git_oid_t oid_type)
624
+ {
625
+ const size_t sha_len = git_oid_hexsize(oid_type);
626
+ const size_t header_len = strlen(header);
627
+
628
+ const char *buffer = *buffer_out;
629
+
630
+ if (buffer + (header_len + sha_len + 1) > buffer_end)
631
+ return -1;
632
+
633
+ if (memcmp(buffer, header, header_len) != 0)
634
+ return -1;
635
+
636
+ if (buffer[header_len + sha_len] != '\n')
637
+ return -1;
638
+
639
+ if (git_oid__fromstr(oid, buffer + header_len, oid_type) < 0)
640
+ return -1;
641
+
642
+ *buffer_out = buffer + (header_len + sha_len + 1);
643
+
644
+ return 0;
645
+ }
646
+
647
+ int git_object__write_oid_header(
648
+ git_str *buf,
649
+ const char *header,
650
+ const git_oid *oid)
651
+ {
652
+ size_t hex_size = git_oid_hexsize(git_oid_type(oid));
653
+ char hex_oid[GIT_OID_MAX_HEXSIZE];
654
+
655
+ if (!hex_size) {
656
+ git_error_set(GIT_ERROR_INVALID, "unknown type");
657
+ return -1;
658
+ }
659
+
660
+ git_oid_fmt(hex_oid, oid);
661
+ git_str_puts(buf, header);
662
+ git_str_put(buf, hex_oid, hex_size);
663
+ git_str_putc(buf, '\n');
664
+
665
+ return git_str_oom(buf) ? -1 : 0;
666
+ }
@@ -33,7 +33,8 @@ int git_object__from_raw(
33
33
  git_object **object_out,
34
34
  const char *data,
35
35
  size_t size,
36
- git_object_t type);
36
+ git_object_t object_type,
37
+ git_oid_t oid_type);
37
38
 
38
39
  int git_object__from_odb_object(
39
40
  git_object **object_out,
@@ -45,9 +46,17 @@ int git_object__resolve_to_type(git_object **obj, git_object_t type);
45
46
 
46
47
  git_object_t git_object_stringn2type(const char *str, size_t len);
47
48
 
48
- int git_oid__parse(git_oid *oid, const char **buffer_out, const char *buffer_end, const char *header);
49
+ int git_object__parse_oid_header(
50
+ git_oid *oid,
51
+ const char **buffer_out,
52
+ const char *buffer_end,
53
+ const char *header,
54
+ git_oid_t oid_type);
49
55
 
50
- void git_oid__writebuf(git_str *buf, const char *header, const git_oid *oid);
56
+ int git_object__write_oid_header(
57
+ git_str *buf,
58
+ const char *header,
59
+ const git_oid *oid);
51
60
 
52
61
  bool git_object__is_valid(
53
62
  git_repository *repo, const git_oid *id, git_object_t expected_type);