odb_loose: SHA256 support for loose object storage Teach the loose object database how to cope with SHA256 objects.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008
diff --git a/include/git2/odb_backend.h b/include/git2/odb_backend.h
index d65aeec..092eb91 100644
--- a/include/git2/odb_backend.h
+++ b/include/git2/odb_backend.h
@@ -59,13 +59,19 @@ typedef struct {
/** Permissions to use creating a file or 0 for defaults */
unsigned int file_mode;
+
+ /**
+ * Type of object IDs to use for this object database, or
+ * 0 for default (currently SHA1).
+ */
+ git_oid_t oid_type;
} git_odb_backend_loose_options;
/* The current version of the diff options structure */
#define GIT_ODB_BACKEND_LOOSE_OPTIONS_VERSION 1
-/* Stack initializer for diff options. Alternatively use
- * `git_diff_options_init` programmatic initialization.
+/* Stack initializer for odb loose backend options. Alternatively use
+ * `git_odb_backend_loose_options_init` programmatic initialization.
*/
#define GIT_ODB_BACKEND_LOOSE_OPTIONS_INIT \
{ GIT_ODB_BACKEND_LOOSE_OPTIONS_VERSION, 0, -1 }
diff --git a/src/libgit2/odb.c b/src/libgit2/odb.c
index 1f9911d..b41ab4a 100644
--- a/src/libgit2/odb.c
+++ b/src/libgit2/odb.c
@@ -663,6 +663,8 @@ int git_odb__add_default_backends(
if (db->do_fsync)
loose_opts.flags |= GIT_ODB_BACKEND_LOOSE_FSYNC;
+ loose_opts.oid_type = db->options.oid_type;
+
/* add the loose object backend */
if (git_odb_backend_loose(&loose, objects_dir, &loose_opts) < 0 ||
add_backend_internal(db, loose, git_odb__loose_priority, as_alternates, inode) < 0)
diff --git a/src/libgit2/odb_loose.c b/src/libgit2/odb_loose.c
index 1885fa2..f47ed50 100644
--- a/src/libgit2/odb_loose.c
+++ b/src/libgit2/odb_loose.c
@@ -47,6 +47,7 @@ typedef struct loose_backend {
git_odb_backend parent;
git_odb_backend_loose_options options;
+ size_t oid_hexsize;
size_t objects_dirlen;
char objects_dir[GIT_FLEX_ARRAY];
@@ -56,13 +57,19 @@ typedef struct loose_backend {
* in order to locate objects matching a short oid.
*/
typedef struct {
+ loose_backend *backend;
+
size_t dir_len;
- unsigned char short_oid[GIT_OID_SHA1_HEXSIZE]; /* hex formatted oid to match */
+
+ /* Hex formatted oid to match (and its length) */
+ unsigned char short_oid[GIT_OID_MAX_HEXSIZE];
size_t short_oid_len;
- int found; /* number of matching
- * objects already found */
- unsigned char res_oid[GIT_OID_SHA1_HEXSIZE]; /* hex formatted oid of
- * the object found */
+
+ /* Number of matching objects found so far */
+ int found;
+
+ /* Hex formatted oid of the object found */
+ unsigned char res_oid[GIT_OID_MAX_HEXSIZE];
} loose_locate_object_state;
@@ -75,20 +82,17 @@ typedef struct {
static int object_file_name(
git_str *name, const loose_backend *be, const git_oid *id)
{
- size_t alloclen;
-
- /* expand length for object root + 40 hex sha1 chars + 2 * '/' + '\0' */
- GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, be->objects_dirlen, GIT_OID_SHA1_HEXSIZE);
- GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, alloclen, 3);
- if (git_str_grow(name, alloclen) < 0)
- return -1;
+ /* append loose object filename: aa/aaa... (41 bytes plus NUL) */
+ size_t path_size = be->oid_hexsize + 1;
git_str_set(name, be->objects_dir, be->objects_dirlen);
git_fs_path_to_dir(name);
- /* loose object filename: aa/aaa... (41 bytes) */
+ if (git_str_grow_by(name, path_size + 1) < 0)
+ return -1;
+
git_oid_pathfmt(name->ptr + name->size, id);
- name->size += GIT_OID_SHA1_HEXSIZE + 1;
+ name->size += path_size;
name->ptr[name->size] = '\0';
return 0;
@@ -460,8 +464,9 @@ static int locate_object(
/* Explore an entry of a directory and see if it matches a short oid */
static int fn_locate_object_short_oid(void *state, git_str *pathbuf) {
loose_locate_object_state *sstate = (loose_locate_object_state *)state;
+ size_t hex_size = sstate->backend->oid_hexsize;
- if (git_str_len(pathbuf) - sstate->dir_len != GIT_OID_SHA1_HEXSIZE - 2) {
+ if (git_str_len(pathbuf) - sstate->dir_len != hex_size - 2) {
/* Entry cannot be an object. Continue to next entry */
return 0;
}
@@ -476,7 +481,9 @@ static int fn_locate_object_short_oid(void *state, git_str *pathbuf) {
if (!sstate->found) {
sstate->res_oid[0] = sstate->short_oid[0];
sstate->res_oid[1] = sstate->short_oid[1];
- memcpy(sstate->res_oid+2, pathbuf->ptr+sstate->dir_len, GIT_OID_SHA1_HEXSIZE-2);
+ memcpy(sstate->res_oid + 2,
+ pathbuf->ptr+sstate->dir_len,
+ hex_size - 2);
}
sstate->found++;
}
@@ -502,7 +509,7 @@ static int locate_object_short_oid(
int error;
/* prealloc memory for OBJ_DIR/xx/xx..38x..xx */
- GIT_ERROR_CHECK_ALLOC_ADD(&alloc_len, dir_len, GIT_OID_SHA1_HEXSIZE);
+ GIT_ERROR_CHECK_ALLOC_ADD(&alloc_len, dir_len, backend->oid_hexsize);
GIT_ERROR_CHECK_ALLOC_ADD(&alloc_len, alloc_len, 3);
if (git_str_grow(object_location, alloc_len) < 0)
return -1;
@@ -526,6 +533,7 @@ static int locate_object_short_oid(
return git_odb__error_notfound("no matching loose object for prefix",
short_oid, len);
+ state.backend = backend;
state.dir_len = git_str_len(object_location);
state.short_oid_len = len;
state.found = 0;
@@ -544,12 +552,12 @@ static int locate_object_short_oid(
return git_odb__error_ambiguous("multiple matches in loose objects");
/* Convert obtained hex formatted oid to raw */
- error = git_oid_fromstr(res_oid, (char *)state.res_oid, GIT_OID_SHA1);
+ error = git_oid_fromstr(res_oid, (char *)state.res_oid, backend->options.oid_type);
if (error)
return error;
/* Update the location according to the oid obtained */
- GIT_ERROR_CHECK_ALLOC_ADD(&alloc_len, dir_len, GIT_OID_SHA1_HEXSIZE);
+ GIT_ERROR_CHECK_ALLOC_ADD(&alloc_len, dir_len, backend->oid_hexsize);
GIT_ERROR_CHECK_ALLOC_ADD(&alloc_len, alloc_len, 2);
git_str_truncate(object_location, dir_len);
@@ -558,20 +566,12 @@ static int locate_object_short_oid(
git_oid_pathfmt(object_location->ptr + dir_len, res_oid);
- object_location->size += GIT_OID_SHA1_HEXSIZE + 1;
+ object_location->size += backend->oid_hexsize + 1;
object_location->ptr[object_location->size] = '\0';
return 0;
}
-
-
-
-
-
-
-
-
/***********************************************************
*
* LOOSE BACKEND PUBLIC API
@@ -594,7 +594,7 @@ static int loose_backend__read_header(size_t *len_p, git_object_t *type_p, git_o
if (locate_object(&object_path, (loose_backend *)backend, oid) < 0) {
error = git_odb__error_notfound("no matching loose object",
- oid, GIT_OID_SHA1_HEXSIZE);
+ oid, ((struct loose_backend *)backend)->oid_hexsize);
} else if ((error = read_header_loose(&raw, &object_path)) == 0) {
*len_p = raw.len;
*type_p = raw.type;
@@ -616,7 +616,7 @@ static int loose_backend__read(void **buffer_p, size_t *len_p, git_object_t *typ
if (locate_object(&object_path, (loose_backend *)backend, oid) < 0) {
error = git_odb__error_notfound("no matching loose object",
- oid, GIT_OID_SHA1_HEXSIZE);
+ oid, ((struct loose_backend *)backend)->oid_hexsize);
} else if ((error = read_loose(&raw, &object_path)) == 0) {
*buffer_p = raw.data;
*len_p = raw.len;
@@ -633,17 +633,19 @@ static int loose_backend__read_prefix(
void **buffer_p,
size_t *len_p,
git_object_t *type_p,
- git_odb_backend *backend,
+ git_odb_backend *_backend,
const git_oid *short_oid,
size_t len)
{
+ struct loose_backend *backend = (struct loose_backend *)_backend;
int error = 0;
- GIT_ASSERT_ARG(len >= GIT_OID_MINPREFIXLEN && len <= GIT_OID_SHA1_HEXSIZE);
+ GIT_ASSERT_ARG(len >= GIT_OID_MINPREFIXLEN &&
+ len <= backend->oid_hexsize);
- if (len == GIT_OID_SHA1_HEXSIZE) {
+ if (len == backend->oid_hexsize) {
/* We can fall back to regular read method */
- error = loose_backend__read(buffer_p, len_p, type_p, backend, short_oid);
+ error = loose_backend__read(buffer_p, len_p, type_p, _backend, short_oid);
if (!error)
git_oid_cpy(out_oid, short_oid);
} else {
@@ -702,15 +704,18 @@ static int loose_backend__exists_prefix(
}
struct foreach_state {
+ struct loose_backend *backend;
size_t dir_len;
git_odb_foreach_cb cb;
void *data;
};
-GIT_INLINE(int) filename_to_oid(git_oid *oid, const char *ptr)
+GIT_INLINE(int) filename_to_oid(struct loose_backend *backend, git_oid *oid, const char *ptr)
{
- int v, i = 0;
- if (strlen(ptr) != GIT_OID_SHA1_HEXSIZE+1)
+ int v;
+ size_t i = 0;
+
+ if (strlen(ptr) != backend->oid_hexsize + 1)
return -1;
if (ptr[2] != '/') {
@@ -724,7 +729,7 @@ GIT_INLINE(int) filename_to_oid(git_oid *oid, const char *ptr)
oid->id[0] = (unsigned char) v;
ptr += 3;
- for (i = 0; i < 38; i += 2) {
+ for (i = 0; i < backend->oid_hexsize - 2; i += 2) {
v = (git__fromhex(ptr[i]) << 4) | git__fromhex(ptr[i + 1]);
if (v < 0)
return -1;
@@ -732,7 +737,7 @@ GIT_INLINE(int) filename_to_oid(git_oid *oid, const char *ptr)
oid->id[1 + i/2] = (unsigned char) v;
}
- oid->type = GIT_OID_SHA1;
+ oid->type = backend->options.oid_type;
return 0;
}
@@ -742,7 +747,7 @@ static int foreach_object_dir_cb(void *_state, git_str *path)
git_oid oid;
struct foreach_state *state = (struct foreach_state *) _state;
- if (filename_to_oid(&oid, path->ptr + state->dir_len) < 0)
+ if (filename_to_oid(state->backend, &oid, path->ptr + state->dir_len) < 0)
return 0;
return git_error_set_after_callback_function(
@@ -779,6 +784,7 @@ static int loose_backend__foreach(git_odb_backend *_backend, git_odb_foreach_cb
return -1;
memset(&state, 0, sizeof(state));
+ state.backend = backend;
state.cb = cb;
state.data = data;
state.dir_len = git_str_len(&buf);
@@ -999,6 +1005,7 @@ static int loose_backend__readstream(
loose_readstream *stream = NULL;
git_hash_ctx *hash_ctx = NULL;
git_str object_path = GIT_STR_INIT;
+ git_hash_algorithm_t algorithm;
obj_hdr hdr;
int error = 0;
@@ -1015,7 +1022,7 @@ static int loose_backend__readstream(
if (locate_object(&object_path, backend, oid) < 0) {
error = git_odb__error_notfound("no matching loose object",
- oid, GIT_OID_SHA1_HEXSIZE);
+ oid, backend->oid_hexsize);
goto done;
}
@@ -1025,9 +1032,11 @@ static int loose_backend__readstream(
hash_ctx = git__malloc(sizeof(git_hash_ctx));
GIT_ERROR_CHECK_ALLOC(hash_ctx);
- if ((error = git_hash_ctx_init(hash_ctx, GIT_HASH_ALGORITHM_SHA1)) < 0 ||
- (error = git_futils_mmap_ro_file(&stream->map, object_path.ptr)) < 0 ||
- (error = git_zstream_init(&stream->zstream, GIT_ZSTREAM_INFLATE)) < 0)
+ algorithm = git_oid_algorithm(backend->options.oid_type);
+
+ if ((error = git_hash_ctx_init(hash_ctx, algorithm)) < 0 ||
+ (error = git_futils_mmap_ro_file(&stream->map, object_path.ptr)) < 0 ||
+ (error = git_zstream_init(&stream->zstream, GIT_ZSTREAM_INFLATE)) < 0)
goto done;
/* check for a packlike loose object */
@@ -1145,6 +1154,9 @@ static void normalize_options(
if (opts->file_mode == 0)
opts->file_mode = GIT_OBJECT_FILE_MODE;
+
+ if (opts->oid_type == 0)
+ opts->oid_type = GIT_OID_DEFAULT;
}
int git_odb_backend_loose(
@@ -1173,6 +1185,7 @@ int git_odb_backend_loose(
backend->objects_dir[backend->objects_dirlen++] = '/';
normalize_options(&backend->options, opts);
+ backend->oid_hexsize = git_oid_hexsize(backend->options.oid_type);
backend->parent.read = &loose_backend__read;
backend->parent.write = &loose_backend__write;
diff --git a/tests/libgit2/odb/loose.c b/tests/libgit2/odb/loose.c
index 20b329f..9f57a68 100644
--- a/tests/libgit2/odb/loose.c
+++ b/tests/libgit2/odb/loose.c
@@ -34,24 +34,27 @@ static void cmp_objects(git_rawobj *o, object_data *d)
static void test_read_object(object_data *data)
{
- git_oid id;
- git_odb_object *obj;
+ git_oid id;
+ git_odb_object *obj;
git_odb *odb;
git_rawobj tmp;
+ git_odb_options opts = GIT_ODB_OPTIONS_INIT;
+
+ opts.oid_type = data->id_type;
- write_object_files(data);
+ write_object_files(data);
- cl_git_pass(git_odb_open(&odb, "test-objects", NULL));
- cl_git_pass(git_oid_fromstr(&id, data->id, GIT_OID_SHA1));
- cl_git_pass(git_odb_read(&obj, odb, &id));
+ cl_git_pass(git_odb_open(&odb, "test-objects", &opts));
+ cl_git_pass(git_oid_fromstr(&id, data->id, data->id_type));
+ cl_git_pass(git_odb_read(&obj, odb, &id));
tmp.data = obj->buffer;
tmp.len = obj->cached.size;
tmp.type = obj->cached.type;
- cmp_objects(&tmp, data);
+ cmp_objects(&tmp, data);
- git_odb_object_free(obj);
+ git_odb_object_free(obj);
git_odb_free(odb);
}
@@ -61,11 +64,14 @@ static void test_read_header(object_data *data)
git_odb *odb;
size_t len;
git_object_t type;
+ git_odb_options opts = GIT_ODB_OPTIONS_INIT;
+
+ opts.oid_type = data->id_type;
write_object_files(data);
- cl_git_pass(git_odb_open(&odb, "test-objects", NULL));
- cl_git_pass(git_oid_fromstr(&id, data->id, GIT_OID_SHA1));
+ cl_git_pass(git_odb_open(&odb, "test-objects", &opts));
+ cl_git_pass(git_oid_fromstr(&id, data->id, data->id_type));
cl_git_pass(git_odb_read_header(&len, &type, odb, &id));
cl_assert_equal_sz(data->dlen, len);
@@ -83,11 +89,14 @@ static void test_readstream_object(object_data *data, size_t blocksize)
char buf[2048], *ptr = buf;
size_t remain;
int ret;
+ git_odb_options opts = GIT_ODB_OPTIONS_INIT;
+
+ opts.oid_type = data->id_type;
write_object_files(data);
- cl_git_pass(git_odb_open(&odb, "test-objects", NULL));
- cl_git_pass(git_oid_fromstr(&id, data->id, GIT_OID_SHA1));
+ cl_git_pass(git_odb_open(&odb, "test-objects", &opts));
+ cl_git_pass(git_oid_fromstr(&id, data->id, data->id_type));
cl_git_pass(git_odb_open_rstream(&stream, &tmp.len, &tmp.type, odb, &id));
remain = tmp.len;
@@ -124,7 +133,7 @@ void test_odb_loose__cleanup(void)
cl_fixture_cleanup("test-objects");
}
-void test_odb_loose__exists(void)
+void test_odb_loose__exists_sha1(void)
{
git_oid id, id2;
git_odb *odb;
@@ -149,7 +158,35 @@ void test_odb_loose__exists(void)
git_odb_free(odb);
}
-void test_odb_loose__simple_reads(void)
+void test_odb_loose__exists_sha256(void)
+{
+ git_oid id, id2;
+ git_odb *odb;
+ git_odb_options odb_opts = GIT_ODB_OPTIONS_INIT;
+
+ odb_opts.oid_type = GIT_OID_SHA256;
+
+ write_object_files(&one_sha256);
+ cl_git_pass(git_odb_open(&odb, "test-objects", &odb_opts));
+
+ cl_git_pass(git_oid_fromstr(&id, one_sha256.id, GIT_OID_SHA256));
+ cl_assert(git_odb_exists(odb, &id));
+
+ cl_git_pass(git_oid_fromstrp(&id, "4c0d52d1", GIT_OID_SHA256));
+ cl_git_pass(git_odb_exists_prefix(&id2, odb, &id, 8));
+ cl_assert_equal_i(0, git_oid_streq(&id2, one_sha256.id));
+
+ /* Test for a missing object */
+ cl_git_pass(git_oid_fromstr(&id, "4c0d52d180c61d01ce1a91dec5ee58f0cbe65fd59433aea803ab927965493faa", GIT_OID_SHA256));
+ cl_assert(!git_odb_exists(odb, &id));
+
+ cl_git_pass(git_oid_fromstrp(&id, "4c0d52da", GIT_OID_SHA256));
+ cl_assert_equal_i(GIT_ENOTFOUND, git_odb_exists_prefix(&id2, odb, &id, 8));
+
+ git_odb_free(odb);
+}
+
+void test_odb_loose__simple_reads_sha1(void)
{
test_read_object(&commit);
test_read_object(&tree);
@@ -160,7 +197,18 @@ void test_odb_loose__simple_reads(void)
test_read_object(&some);
}
-void test_odb_loose__streaming_reads(void)
+void test_odb_loose__simple_reads_sha256(void)
+{
+ test_read_object(&commit_sha256);
+ test_read_object(&tree_sha256);
+ test_read_object(&tag_sha256);
+ test_read_object(&zero_sha256);
+ test_read_object(&one_sha256);
+ test_read_object(&two_sha256);
+ test_read_object(&some_sha256);
+}
+
+void test_odb_loose__streaming_reads_sha1(void)
{
size_t blocksizes[] = { 1, 2, 4, 16, 99, 1024, 123456789 };
size_t i;
@@ -176,7 +224,23 @@ void test_odb_loose__streaming_reads(void)
}
}
-void test_odb_loose__read_header(void)
+void test_odb_loose__streaming_reads_sha256(void)
+{
+ size_t blocksizes[] = { 1, 2, 4, 16, 99, 1024, 123456789 };
+ size_t i;
+
+ for (i = 0; i < ARRAY_SIZE(blocksizes); i++) {
+ test_readstream_object(&commit_sha256, blocksizes[i]);
+ test_readstream_object(&tree_sha256, blocksizes[i]);
+ test_readstream_object(&tag_sha256, blocksizes[i]);
+ test_readstream_object(&zero_sha256, blocksizes[i]);
+ test_readstream_object(&one_sha256, blocksizes[i]);
+ test_readstream_object(&two_sha256, blocksizes[i]);
+ test_readstream_object(&some_sha256, blocksizes[i]);
+ }
+}
+
+void test_odb_loose__read_header_sha1(void)
{
test_read_header(&commit);
test_read_header(&tree);
@@ -187,6 +251,17 @@ void test_odb_loose__read_header(void)
test_read_header(&some);
}
+void test_odb_loose__read_header_sha256(void)
+{
+ test_read_header(&commit_sha256);
+ test_read_header(&tree_sha256);
+ test_read_header(&tag_sha256);
+ test_read_header(&zero_sha256);
+ test_read_header(&one_sha256);
+ test_read_header(&two_sha256);
+ test_read_header(&some_sha256);
+}
+
static void test_write_object_permission(
mode_t dir_mode, mode_t file_mode,
mode_t expected_dir_mode, mode_t expected_file_mode)
diff --git a/tests/libgit2/odb/loose_data.h b/tests/libgit2/odb/loose_data.h
index c10c9bc..97681a0 100644
--- a/tests/libgit2/odb/loose_data.h
+++ b/tests/libgit2/odb/loose_data.h
@@ -1,7 +1,8 @@
typedef struct object_data {
unsigned char *bytes; /* (compressed) bytes stored in object store */
size_t blen; /* length of data in object store */
- char *id; /* object id (sha1) */
+ char *id; /* object id (hex chars) */
+ git_oid_t id_type; /* type of object id (sha1 or sha256) */
char *type; /* object type */
char *dir; /* object store (fan-out) directory name */
char *file; /* object store filename */
@@ -9,7 +10,10 @@ typedef struct object_data {
size_t dlen; /* length of (uncompressed) object data */
} object_data;
-/* one == 8b137891791fe96927ad78e64b0aad7bded08bdc */
+/*
+ * one == 8b137891791fe96927ad78e64b0aad7bded08bdc (sha1)
+ * 4c0d52d180c61d01ce1a91dec5ee58f0cbe65fd59433aea803ab927965493fd7 (sha256)
+ */
static unsigned char one_bytes[] = {
0x31, 0x78, 0x9c, 0xe3, 0x02, 0x00, 0x00, 0x0b,
0x00, 0x0b,
@@ -23,6 +27,7 @@ static object_data one = {
one_bytes,
sizeof(one_bytes),
"8b137891791fe96927ad78e64b0aad7bded08bdc",
+ GIT_OID_SHA1,
"blob",
"test-objects/8b",
"test-objects/8b/137891791fe96927ad78e64b0aad7bded08bdc",
@@ -30,8 +35,23 @@ static object_data one = {
sizeof(one_data),
};
+static object_data one_sha256 = {
+ one_bytes,
+ sizeof(one_bytes),
+ "4c0d52d180c61d01ce1a91dec5ee58f0cbe65fd59433aea803ab927965493fd7",
+ GIT_OID_SHA256,
+ "blob",
+ "test-objects/4c",
+ "test-objects/4c/0d52d180c61d01ce1a91dec5ee58f0cbe65fd59433aea803ab927965493fd7",
+ one_data,
+ sizeof(one_data),
+};
-/* commit == 3d7f8a6af076c8c3f20071a8935cdbe8228594d1 */
+
+/*
+ * commit == 3d7f8a6af076c8c3f20071a8935cdbe8228594d1 (sha1)
+ * a2a430fb63b294f868af4ef6ccc9c3e8256e370859ce578a23837ac85337f562 (sha256)
+ */
static unsigned char commit_bytes[] = {
0x78, 0x01, 0x85, 0x50, 0xc1, 0x6a, 0xc3, 0x30,
0x0c, 0xdd, 0xd9, 0x5f, 0xa1, 0xfb, 0x96, 0x12,
@@ -64,6 +84,40 @@ static unsigned char commit_bytes[] = {
0x1f, 0x78, 0x35,
};
+static unsigned char commit_bytes_sha256[] = {
+ 0x78, 0x01, 0x85, 0x90, 0xc1, 0x4e, 0xc3, 0x30,
+ 0x0c, 0x86, 0x39, 0xe7, 0x29, 0x7c, 0x87, 0x4e,
+ 0x5d, 0x93, 0xa6, 0x2d, 0x9a, 0x10, 0x13, 0x67,
+ 0xc4, 0x81, 0xf1, 0x00, 0x4e, 0xe3, 0xb4, 0x91,
+ 0x9a, 0xa4, 0x4a, 0x53, 0x69, 0x7d, 0x7b, 0x82,
+ 0x3a, 0x4d, 0x9c, 0xc0, 0xa7, 0xcf, 0xbf, 0xfd,
+ 0xff, 0xb2, 0xdc, 0x07, 0xe7, 0x6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8, 0xa7, 0x1d, 0x3c, 0xe9,
+ 0x22, 0x98, 0x42, 0x6d, 0xcf, 0x7f, 0xbf, 0x83,
+ 0x7d, 0x03, 0x6d, 0x1e, 0x7e, 0xa9
+};
+
static unsigned char commit_data[] = {
0x74, 0x72, 0x65, 0x65, 0x20, 0x64, 0x66, 0x66,
0x32, 0x64, 0x61, 0x39, 0x30, 0x62, 0x32, 0x35,
@@ -112,10 +166,62 @@ static unsigned char commit_data[] = {
0x3e, 0x0a,
};
+static unsigned char commit_data_sha256[] = {
+ 0x74, 0x72, 0x65, 0x65, 0x20, 0x33, 0x34, 0x61,
+ 0x34, 0x38, 0x35, 0x34, 0x62, 0x35, 0x34, 0x32,
+ 0x36, 0x66, 0x39, 0x32, 0x34, 0x36, 0x30, 0x62,
+ 0x34, 0x61, 0x65, 0x33, 0x35, 0x65, 0x36, 0x64,
+ 0x37, 0x39, 0x37, 0x34, 0x36, 0x62, 0x65, 0x36,
+ 0x36, 0x63, 0x33, 0x38, 0x62, 0x66, 0x66, 0x64,
+ 0x36, 0x65, 0x66, 0x33, 0x62, 0x63, 0x34, 0x66,
+ 0x30, 0x35, 0x33, 0x65, 0x64, 0x37, 0x38, 0x61,
+ 0x33, 0x36, 0x62, 0x61, 0x34, 0x0a, 0x61, 0x75,
+ 0x74, 0x68, 0x6f, 0x72, 0x20, 0x41, 0x20, 0x55,
+ 0x20, 0x54, 0x68, 0x6f, 0x72, 0x20, 0x3c, 0x61,
+ 0x75, 0x74, 0x68, 0x6f, 0x72, 0x40, 0x65, 0x78,
+ 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2e, 0x63, 0x6f,
+ 0x6d, 0x3e, 0x20, 0x31, 0x32, 0x32, 0x37, 0x38,
+ 0x31, 0x34, 0x32, 0x39, 0x37, 0x20, 0x2b, 0x30,
+ 0x30, 0x30, 0x30, 0x0a, 0x63, 0x6f, 0x6d, 0x6d,
+ 0x69, 0x74, 0x74, 0x65, 0x72, 0x20, 0x43, 0x20,
+ 0x4f, 0x20, 0x4d, 0x69, 0x74, 0x74, 0x65, 0x72,
+ 0x20, 0x3c, 0x63, 0x6f, 0x6d, 0x6d, 0x69, 0x74,
+ 0x74, 0x65, 0x72, 0x40, 0x65, 0x78, 0x61, 0x6d,
+ 0x70, 0x6c, 0x65, 0x2e, 0x63, 0x6f, 0x6d, 0x3e,
+ 0x20, 0x31, 0x32, 0x32, 0x37, 0x38, 0x31, 0x34,
+ 0x32, 0x39, 0x37, 0x20, 0x2b, 0x30, 0x30, 0x30,
+ 0x30, 0x0a, 0x0a, 0x41, 0x20, 0x6f, 0x6e, 0x65,
+ 0x2d, 0x6c, 0x69, 0x6e, 0x65, 0x20, 0x63, 0x6f,
+ 0x6d, 0x6d, 0x69, 0x74, 0x20, 0x73, 0x75, 0x6d,
+ 0x6d, 0x61, 0x72, 0x79, 0x0a, 0x0a, 0x54, 0x68,
+ 0x65, 0x20, 0x62, 0x6f, 0x64, 0x79, 0x20, 0x6f,
+ 0x66, 0x20, 0x74, 0x68, 0x65, 0x20, 0x63, 0x6f,
+ 0x6d, 0x6d, 0x69, 0x74, 0x20, 0x6d, 0x65, 0x73,
+ 0x73, 0x61, 0x67, 0x65, 0x2c, 0x20, 0x63, 0x6f,
+ 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x69, 0x6e, 0x67,
+ 0x20, 0x66, 0x75, 0x72, 0x74, 0x68, 0x65, 0x72,
+ 0x20, 0x65, 0x78, 0x70, 0x6c, 0x61, 0x6e, 0x61,
+ 0x74, 0x69, 0x6f, 0x6e, 0x0a, 0x6f, 0x66, 0x20,
+ 0x74, 0x68, 0x65, 0x20, 0x70, 0x75, 0x72, 0x70,
+ 0x6f, 0x73, 0x65, 0x20, 0x6f, 0x66, 0x20, 0x74,
+ 0x68, 0x65, 0x20, 0x63, 0x68, 0x61, 0x6e, 0x67,
+ 0x65, 0x73, 0x20, 0x69, 0x6e, 0x74, 0x72, 0x6f,
+ 0x64, 0x75, 0x63, 0x65, 0x64, 0x20, 0x62, 0x79,
+ 0x20, 0x74, 0x68, 0x65, 0x20, 0x63, 0x6f, 0x6d,
+ 0x6d, 0x69, 0x74, 0x2e, 0x0a, 0x0a, 0x53, 0x69,
+ 0x67, 0x6e, 0x65, 0x64, 0x2d, 0x6f, 0x66, 0x2d,
+ 0x62, 0x79, 0x3a, 0x20, 0x41, 0x20, 0x55, 0x20,
+ 0x54, 0x68, 0x6f, 0x72, 0x20, 0x3c, 0x61, 0x75,
+ 0x74, 0x68, 0x6f, 0x72, 0x40, 0x65, 0x78, 0x61,
+ 0x6d, 0x70, 0x6c, 0x65, 0x2e, 0x63, 0x6f, 0x6d,
+ 0x3e, 0x0a
+};
+
static object_data commit = {
commit_bytes,
sizeof(commit_bytes),
"3d7f8a6af076c8c3f20071a8935cdbe8228594d1",
+ GIT_OID_SHA1,
"commit",
"test-objects/3d",
"test-objects/3d/7f8a6af076c8c3f20071a8935cdbe8228594d1",
@@ -123,7 +229,22 @@ static object_data commit = {
sizeof(commit_data),
};
-/* tree == dff2da90b254e1beb889d1f1f1288be1803782df */
+static object_data commit_sha256 = {
+ commit_bytes_sha256,
+ sizeof(commit_bytes_sha256),
+ "a2a430fb63b294f868af4ef6ccc9c3e8256e370859ce578a23837ac85337f562",
+ GIT_OID_SHA256,
+ "commit",
+ "test-objects/a2",
+ "test-objects/a2/a430fb63b294f868af4ef6ccc9c3e8256e370859ce578a23837ac85337f562",
+ commit_data_sha256,
+ sizeof(commit_data_sha256),
+};
+
+/*
+ * tree == dff2da90b254e1beb889d1f1f1288be1803782df (sha1)
+ * 34a4854b5426f92460b4ae35e6d79746be66c38bffd6ef3bc4f053ed78a36ba4 (sha256)
+ */
static unsigned char tree_bytes[] = {
0x78, 0x01, 0x2b, 0x29, 0x4a, 0x4d, 0x55, 0x30,
0x34, 0x32, 0x63, 0x30, 0x34, 0x30, 0x30, 0x33,
@@ -163,10 +284,74 @@ static unsigned char tree_data[] = {
0xd8, 0xc2, 0xe4, 0x8c, 0x53, 0x91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 0x56, 0x40, 0xd1,
+ 0x71, 0xe7, 0xaa, 0x66, 0x7b, 0x0b, 0x32, 0x00,
+ 0x70, 0x06, 0xf7, 0x86, 0x71, 0x10, 0x32, 0xeb,
+ 0xb8, 0x29, 0x31, 0xcc, 0xa6, 0x9c, 0xc1, 0x5b,
+ 0x31, 0x30, 0x30, 0x36, 0x34, 0x34, 0x20, 0x74,
+ 0x77, 0x6f, 0x00, 0xf8, 0x62, 0x5e, 0x43, 0xf9,
+ 0xe0, 0x4f, 0x24, 0x29, 0x1f, 0x77, 0xcd, 0xbe,
+ 0x4c, 0x71, 0xb3, 0xc2, 0xa3, 0xb0, 0x00, 0x3f,
+ 0x60, 0x41, 0x9b, 0x3e, 0xd0, 0x6a, 0x05, 0x8d,
+ 0x76, 0x6c, 0x8b, 0x31, 0x30, 0x30, 0x36, 0x34,
+ 0x34, 0x20, 0x7a, 0x65, 0x72, 0x6f, 0x00, 0x44,
+ 0x9e, 0x9b, 0x79, 0x54, 0x20, 0xcd, 0x16, 0xfe,
+ 0x60, 0xad, 0x52, 0x98, 0xcf, 0x68, 0x0f, 0x15,
+ 0xa7, 0xcd, 0x2a, 0xc9, 0xb4, 0x4a, 0xda, 0xf7,
+ 0xed, 0x3e, 0xdc, 0x0d, 0x08, 0xdd, 0x78
+};
+
static object_data tree = {
tree_bytes,
sizeof(tree_bytes),
"dff2da90b254e1beb889d1f1f1288be1803782df",
+ GIT_OID_SHA1,
"tree",
"test-objects/df",
"test-objects/df/f2da90b254e1beb889d1f1f1288be1803782df",
@@ -174,7 +359,22 @@ static object_data tree = {
sizeof(tree_data),
};
-/* tag == 09d373e1dfdc16b129ceec6dd649739911541e05 */
+static object_data tree_sha256 = {
+ tree_bytes_sha256,
+ sizeof(tree_bytes_sha256),
+ "34a4854b5426f92460b4ae35e6d79746be66c38bffd6ef3bc4f053ed78a36ba4",
+ GIT_OID_SHA256,
+ "tree",
+ "test-objects/34",
+ "test-objects/34/a4854b5426f92460b4ae35e6d79746be66c38bffd6ef3bc4f053ed78a36ba4",
+ tree_data_sha256,
+ sizeof(tree_data_sha256),
+};
+
+/*
+ * tag == 09d373e1dfdc16b129ceec6dd649739911541e05 (sha1)
+ * f535d7595d5d0e5e530b5deb34542c96491fea300a1318036b605306548cb225 (sha256)
+ */
static unsigned char tag_bytes[] = {
0x78, 0x01, 0x35, 0x4e, 0xcb, 0x0a, 0xc2, 0x40,
0x10, 0xf3, 0xbc, 0x5f, 0x31, 0x77, 0xa1, 0xec,
@@ -222,10 +422,99 @@ static unsigned char tag_data[] = {
0x2e, 0x30, 0x2e, 0x31, 0x0a,
};
+static unsigned char tag_bytes_sha256[] = {
+ 0x78, 0x01, 0x55, 0x8f, 0xd1, 0x4e, 0x84, 0x30,
+ 0x10, 0x45, 0x7d, 0xee, 0x57, 0xcc, 0xbb, 0x2e,
+ 0x81, 0x16, 0x68, 0x31, 0x1b, 0xa3, 0xf1, 0xd9,
+ 0xf8, 0xe0, 0xfa, 0x01, 0x43, 0x99, 0x42, 0x0d,
+ 0xb4, 0xa4, 0x14, 0xb3, 0xfc, 0xbd, 0xc5, 0xdd,
+ 0x4d, 0xb4, 0x69, 0xd2, 0x9b, 0xc9, 0xdc, 0x7b,
+ 0x6e, 0x23, 0xf6, 0x20, 0xa4, 0xba, 0xf3, 0xed,
+ 0x17, 0xe9, 0x08, 0xc8, 0xb1, 0x14, 0xb9, 0x69,
+ 0x6b, 0xd1, 0xf2, 0xa6, 0x34, 0xaa, 0x56, 0x68,
+ 0x4a, 0x32, 0xb5, 0xd6, 0xba, 0xd1, 0x82, 0x14,
+ 0xaf, 0x6a, 0x12, 0x32, 0x57, 0x55, 0xa3, 0xa9,
+ 0x92, 0x0a, 0xb9, 0x50, 0x42, 0xa2, 0x56, 0x95,
+ 0x10, 0xd2, 0x54, 0x35, 0x67, 0x71, 0x9b, 0x09,
+ 0xb4, 0x9f, 0x26, 0x1b, 0x59, 0x4c, 0xd9, 0xdf,
+ 0x79, 0x96, 0x67, 0xc5, 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0x62, 0x32, 0x39, 0x34, 0x66, 0x38, 0x36,
+ 0x38, 0x61, 0x66, 0x34, 0x65, 0x66, 0x36, 0x63,
+ 0x63, 0x63, 0x39, 0x63, 0x33, 0x65, 0x38, 0x32,
+ 0x35, 0x36, 0x65, 0x33, 0x37, 0x30, 0x38, 0x35,
+ 0x39, 0x63, 0x65, 0x35, 0x37, 0x38, 0x61, 0x32,
+ 0x33, 0x38, 0x33, 0x37, 0x61, 0x63, 0x38, 0x35,
+ 0x33, 0x33, 0x37, 0x66, 0x35, 0x36, 0x32, 0x0a,
+ 0x74, 0x79, 0x70, 0x65, 0x20, 0x63, 0x6f, 0x6d,
+ 0x6d, 0x69, 0x74, 0x0a, 0x74, 0x61, 0x67, 0x20,
+ 0x76, 0x30, 0x2e, 0x30, 0x2e, 0x31, 0x0a, 0x74,
+ 0x61, 0x67, 0x67, 0x65, 0x72, 0x20, 0x43, 0x20,
+ 0x4f, 0x20, 0x4d, 0x69, 0x74, 0x74, 0x65, 0x72,
+ 0x20, 0x3c, 0x63, 0x6f, 0x6d, 0x6d, 0x69, 0x74,
+ 0x74, 0x65, 0x72, 0x40, 0x65, 0x78, 0x61, 0x6d,
+ 0x70, 0x6c, 0x65, 0x2e, 0x63, 0x6f, 0x6d, 0x3e,
+ 0x20, 0x31, 0x32, 0x32, 0x37, 0x38, 0x31, 0x34,
+ 0x32, 0x39, 0x37, 0x20, 0x2b, 0x30, 0x30, 0x30,
+ 0x30, 0x0a, 0x0a, 0x54, 0x68, 0x69, 0x73, 0x20,
+ 0x69, 0x73, 0x20, 0x74, 0x68, 0x65, 0x20, 0x74,
+ 0x61, 0x67, 0x20, 0x6f, 0x62, 0x6a, 0x65, 0x63,
+ 0x74, 0x20, 0x66, 0x6f, 0x72, 0x20, 0x72, 0x65,
+ 0x6c, 0x65, 0x61, 0x73, 0x65, 0x20, 0x76, 0x30,
+ 0x2e, 0x30, 0x2e, 0x31, 0x0a, 0x20, 0x63, 0x6f,
+ 0x6d, 0x6d, 0x69, 0x74, 0x20, 0x73, 0x75, 0x6d,
+ 0x6d, 0x61, 0x72, 0x79, 0x0a, 0x0a, 0x54, 0x68,
+ 0x65, 0x20, 0x62, 0x6f, 0x64, 0x79, 0x20, 0x6f,
+ 0x66, 0x20, 0x74, 0x68, 0x65, 0x20, 0x63, 0x6f,
+ 0x6d, 0x6d, 0x69, 0x74, 0x20, 0x6d, 0x65, 0x73,
+ 0x73, 0x61, 0x67, 0x65, 0x2c, 0x20, 0x63, 0x6f,
+ 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x69, 0x6e, 0x67,
+ 0x20, 0x66, 0x75, 0x72, 0x74, 0x68, 0x65, 0x72,
+ 0x20, 0x65, 0x78, 0x70, 0x6c, 0x61, 0x6e, 0x61,
+ 0x74, 0x69, 0x6f, 0x6e, 0x0a, 0x6f, 0x66, 0x20,
+ 0x74, 0x68, 0x65, 0x20, 0x70, 0x75, 0x72, 0x70,
+ 0x6f, 0x73, 0x65, 0x20, 0x6f, 0x66, 0x20, 0x74,
+ 0x68, 0x65, 0x20, 0x63, 0x68, 0x61, 0x6e, 0x67,
+ 0x65, 0x73, 0x20, 0x69, 0x6e, 0x74, 0x72, 0x6f,
+ 0x64, 0x75, 0x63, 0x65, 0x64, 0x20, 0x62, 0x79,
+ 0x20, 0x74, 0x68, 0x65, 0x20, 0x63, 0x6f, 0x6d,
+ 0x6d, 0x69, 0x74, 0x2e, 0x0a, 0x0a, 0x53, 0x69,
+ 0x67, 0x6e, 0x65, 0x64, 0x2d, 0x6f, 0x66, 0x2d,
+ 0x62, 0x79, 0x3a, 0x20, 0x41, 0x20, 0x55, 0x20,
+ 0x54, 0x68, 0x6f, 0x72, 0x20, 0x3c, 0x61, 0x75,
+ 0x74, 0x68, 0x6f, 0x72, 0x40, 0x65, 0x78, 0x61,
+ 0x6d, 0x70, 0x6c, 0x65, 0x2e, 0x63, 0x6f, 0x6d,
+ 0x3e, 0x0a
+};
+
static object_data tag = {
tag_bytes,
sizeof(tag_bytes),
"09d373e1dfdc16b129ceec6dd649739911541e05",
+ GIT_OID_SHA1,
"tag",
"test-objects/09",
"test-objects/09/d373e1dfdc16b129ceec6dd649739911541e05",
@@ -233,7 +522,22 @@ static object_data tag = {
sizeof(tag_data),
};
-/* zero == e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 */
+static object_data tag_sha256 = {
+ tag_bytes_sha256,
+ sizeof(tag_bytes_sha256),
+ "f535d7595d5d0e5e530b5deb34542c96491fea300a1318036b605306548cb225",
+ GIT_OID_SHA256,
+ "tag",
+ "test-objects/f5",
+ "test-objects/f5/35d7595d5d0e5e530b5deb34542c96491fea300a1318036b605306548cb225",
+ tag_data_sha256,
+ sizeof(tag_data_sha256),
+};
+
+/*
+ * zero == e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 (sha1)
+ * 473a0f4c3be8a93681a267e3b1e9a7dcda1185436fe141f7749120a303721813 (sha256)
+ */
static unsigned char zero_bytes[] = {
0x78, 0x01, 0x4b, 0xca, 0xc9, 0x4f, 0x52, 0x30,
0x60, 0x00, 0x00, 0x09, 0xb0, 0x01, 0xf0,
@@ -247,6 +551,7 @@ static object_data zero = {
zero_bytes,
sizeof(zero_bytes),
"e69de29bb2d1d6434b8b29ae775ad8c2e48c5391",
+ GIT_OID_SHA1,
"blob",
"test-objects/e6",
"test-objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391",
@@ -254,7 +559,22 @@ static object_data zero = {
0,
};
-/* two == 78981922613b2afb6025042ff6bd878ac1994e85 */
+static object_data zero_sha256 = {
+ zero_bytes,
+ sizeof(zero_bytes),
+ "473a0f4c3be8a93681a267e3b1e9a7dcda1185436fe141f7749120a303721813",
+ GIT_OID_SHA256,
+ "blob",
+ "test-objects/47",
+ "test-objects/47/3a0f4c3be8a93681a267e3b1e9a7dcda1185436fe141f7749120a303721813",
+ zero_data,
+ 0,
+};
+
+/*
+ * two == 78981922613b2afb6025042ff6bd878ac1994e85 (sha1)
+ * f8625e43f9e04f24291f77cdbe4c71b3c2a3b0003f60419b3ed06a058d766c8b (sha256)
+ */
static unsigned char two_bytes[] = {
0x78, 0x01, 0x4b, 0xca, 0xc9, 0x4f, 0x52, 0x30,
0x62, 0x48, 0xe4, 0x02, 0x00, 0x0e, 0x64, 0x02,
@@ -269,6 +589,7 @@ static object_data two = {
two_bytes,
sizeof(two_bytes),
"78981922613b2afb6025042ff6bd878ac1994e85",
+ GIT_OID_SHA1,
"blob",
"test-objects/78",
"test-objects/78/981922613b2afb6025042ff6bd878ac1994e85",
@@ -276,7 +597,22 @@ static object_data two = {
sizeof(two_data),
};
-/* some == fd8430bc864cfcd5f10e5590f8a447e01b942bfe */
+static object_data two_sha256 = {
+ two_bytes,
+ sizeof(two_bytes),
+ "f8625e43f9e04f24291f77cdbe4c71b3c2a3b0003f60419b3ed06a058d766c8b",
+ GIT_OID_SHA256,
+ "blob",
+ "test-objects/f8",
+ "test-objects/f8/625e43f9e04f24291f77cdbe4c71b3c2a3b0003f60419b3ed06a058d766c8b",
+ two_data,
+ sizeof(two_data),
+};
+
+/*
+ * some == fd8430bc864cfcd5f10e5590f8a447e01b942bfe (sha1)
+ * 083c2b8b445640d171e7aa667b0b32007006f786711032ebb82931cca69cc15b (sha256)
+ */
static unsigned char some_bytes[] = {
0x78, 0x01, 0x7d, 0x54, 0xc1, 0x4e, 0xe3, 0x30,
0x10, 0xdd, 0x33, 0x5f, 0x31, 0xc7, 0x5d, 0x94,
@@ -514,9 +850,22 @@ static object_data some = {
some_bytes,
sizeof(some_bytes),
"fd8430bc864cfcd5f10e5590f8a447e01b942bfe",
+ GIT_OID_SHA1,
"blob",
"test-objects/fd",
"test-objects/fd/8430bc864cfcd5f10e5590f8a447e01b942bfe",
some_data,
sizeof(some_data),
};
+
+static object_data some_sha256 = {
+ some_bytes,
+ sizeof(some_bytes),
+ "083c2b8b445640d171e7aa667b0b32007006f786711032ebb82931cca69cc15b",
+ GIT_OID_SHA256,
+ "blob",
+ "test-objects/08",
+ "test-objects/08/3c2b8b445640d171e7aa667b0b32007006f786711032ebb82931cca69cc15b",
+ some_data,
+ sizeof(some_data),
+};