diff options
author | Edward Thomson <ethomson@edwardthomson.com> | 2022-01-26 13:07:28 -0500 |
---|---|---|
committer | Edward Thomson <ethomson@edwardthomson.com> | 2022-07-07 23:17:08 -0400 |
commit | a37f347b65295c3d90ea6f90c12eaf9e5b0b5523 (patch) | |
tree | 4684800625c0e7ea459a703b872f39fdffa74e78 | |
parent | e3343203aa2e322764ce68f04795137df6800f6f (diff) | |
download | libgit2-a37f347b65295c3d90ea6f90c12eaf9e5b0b5523.tar.gz |
odb_hash*: accept the oid type to hash into
The git_odb_hash helper functions should not assume SHA1, and instead
should be given the oid type that they're producing.
-rw-r--r-- | fuzzers/packfile_fuzzer.c | 2 | ||||
-rw-r--r-- | include/git2/odb.h | 25 | ||||
-rw-r--r-- | src/cli/cmd_hash_object.c | 2 | ||||
-rw-r--r-- | src/libgit2/diff_file.c | 5 | ||||
-rw-r--r-- | src/libgit2/diff_generate.c | 5 | ||||
-rw-r--r-- | src/libgit2/indexer.c | 2 | ||||
-rw-r--r-- | src/libgit2/iterator.c | 2 | ||||
-rw-r--r-- | src/libgit2/object.c | 3 | ||||
-rw-r--r-- | src/libgit2/odb.c | 95 | ||||
-rw-r--r-- | src/libgit2/odb.h | 18 | ||||
-rw-r--r-- | src/libgit2/reader.c | 2 | ||||
-rw-r--r-- | src/libgit2/repository.c | 2 | ||||
-rw-r--r-- | tests/libgit2/checkout/binaryunicode.c | 4 | ||||
-rw-r--r-- | tests/libgit2/object/raw/hash.c | 4 | ||||
-rw-r--r-- | tests/libgit2/repo/hashfile.c | 40 | ||||
-rw-r--r-- | tests/libgit2/status/single.c | 4 |
16 files changed, 136 insertions, 79 deletions
diff --git a/fuzzers/packfile_fuzzer.c b/fuzzers/packfile_fuzzer.c index 7f448f6a4..3d6d9a3d8 100644 --- a/fuzzers/packfile_fuzzer.c +++ b/fuzzers/packfile_fuzzer.c @@ -90,7 +90,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) if (git_indexer_append(indexer, data, size, &stats) < 0) goto cleanup; if (append_hash) { - if (git_odb_hash(&oid, data, size, GIT_OBJECT_BLOB) < 0) { + if (git_odb_hash(&oid, data, size, GIT_OBJECT_BLOB, GIT_OID_SHA1) < 0) { fprintf(stderr, "Failed to compute the SHA1 hash\n"); abort(); } diff --git a/include/git2/odb.h b/include/git2/odb.h index 54c38a477..61e04d190 100644 --- a/include/git2/odb.h +++ b/include/git2/odb.h @@ -435,18 +435,24 @@ GIT_EXTERN(int) git_odb_write_multi_pack_index( git_odb *db); /** - * Determine the object-ID (sha1 hash) of a data buffer + * Determine the object-ID (sha1 or sha256 hash) of a data buffer * - * The resulting SHA-1 OID will be the identifier for the data - * buffer as if the data buffer it were to written to the ODB. + * The resulting OID will be the identifier for the data buffer as if + * the data buffer it were to written to the ODB. * * @param out the resulting object-ID. * @param data data to hash * @param len size of the data - * @param type of the data to hash + * @param object_type of the data to hash + * @param oid_type the oid type to hash to * @return 0 or an error code */ -GIT_EXTERN(int) git_odb_hash(git_oid *out, const void *data, size_t len, git_object_t type); +GIT_EXTERN(int) git_odb_hash( + git_oid *out, + const void *data, + size_t len, + git_object_t object_type, + git_oid_t oid_type); /** * Read a file from disk and fill a git_oid with the object id @@ -458,10 +464,15 @@ GIT_EXTERN(int) git_odb_hash(git_oid *out, const void *data, size_t len, git_obj * * @param out oid structure the result is written into. * @param path file to read and determine object id for - * @param type the type of the object that will be hashed + * @param object_type of the data to hash + * @param oid_type the oid type to hash to * @return 0 or an error code */ -GIT_EXTERN(int) git_odb_hashfile(git_oid *out, const char *path, git_object_t type); +GIT_EXTERN(int) git_odb_hashfile( + git_oid *out, + const char *path, + git_object_t object_type, + git_oid_t oid_type); /** * Create a copy of an odb_object diff --git a/src/cli/cmd_hash_object.c b/src/cli/cmd_hash_object.c index 5cfe9146a..72fbef9e6 100644 --- a/src/cli/cmd_hash_object.c +++ b/src/cli/cmd_hash_object.c @@ -64,7 +64,7 @@ static int hash_buf(git_odb *odb, git_str *buf, git_object_t type) if (git_odb_write(&oid, odb, buf->ptr, buf->size, type) < 0) return cli_error_git(); } else { - if (git_odb_hash(&oid, buf->ptr, buf->size, type) < 0) + if (git_odb_hash(&oid, buf->ptr, buf->size, type, GIT_OID_SHA1) < 0) return cli_error_git(); } diff --git a/src/libgit2/diff_file.c b/src/libgit2/diff_file.c index 397165577..4d63317eb 100644 --- a/src/libgit2/diff_file.c +++ b/src/libgit2/diff_file.c @@ -162,7 +162,7 @@ int git_diff_file_content__init_from_src( fc->flags |= GIT_DIFF_FLAG__FREE_BLOB; } else { int error; - if ((error = git_odb_hash(&fc->file->id, src->buf, src->buflen, GIT_OBJECT_BLOB)) < 0) + if ((error = git_odb_hash(&fc->file->id, src->buf, src->buflen, GIT_OBJECT_BLOB, GIT_OID_SHA1)) < 0) return error; fc->file->size = src->buflen; fc->file->id_abbrev = GIT_OID_SHA1_HEXSIZE; @@ -412,7 +412,8 @@ static int diff_file_content_load_workdir( /* once data is loaded, update OID if we didn't have it previously */ if (!error && (fc->file->flags & GIT_DIFF_FLAG_VALID_ID) == 0) { error = git_odb_hash( - &fc->file->id, fc->map.data, fc->map.len, GIT_OBJECT_BLOB); + &fc->file->id, fc->map.data, fc->map.len, + GIT_OBJECT_BLOB, GIT_OID_SHA1); fc->file->flags |= GIT_DIFF_FLAG_VALID_ID; } diff --git a/src/libgit2/diff_generate.c b/src/libgit2/diff_generate.c index d22c55701..a88ce8c32 100644 --- a/src/libgit2/diff_generate.c +++ b/src/libgit2/diff_generate.c @@ -660,7 +660,7 @@ int git_diff__oid_for_entry( git_error_clear(); } } else if (S_ISLNK(mode)) { - error = git_odb__hashlink(out, full_path.ptr); + error = git_odb__hashlink(out, full_path.ptr, GIT_OID_SHA1); diff->base.perf.oid_calculations++; } else if (!git__is_sizet(entry.file_size)) { git_error_set(GIT_ERROR_NOMEMORY, "file size overflow (for 32-bits) on '%s'", @@ -675,7 +675,8 @@ int git_diff__oid_for_entry( error = fd; else { error = git_odb__hashfd_filtered( - out, fd, (size_t)entry.file_size, GIT_OBJECT_BLOB, fl); + out, fd, (size_t)entry.file_size, + GIT_OBJECT_BLOB, GIT_OID_SHA1, fl); p_close(fd); diff->base.perf.oid_calculations++; } diff --git a/src/libgit2/indexer.c b/src/libgit2/indexer.c index e7ea77ee9..c35e659e5 100644 --- a/src/libgit2/indexer.c +++ b/src/libgit2/indexer.c @@ -546,7 +546,7 @@ static int hash_and_save(git_indexer *idx, git_rawobj *obj, off64_t entry_start) entry = git__calloc(1, sizeof(*entry)); GIT_ERROR_CHECK_ALLOC(entry); - if (git_odb__hashobj(&oid, obj) < 0) { + if (git_odb__hashobj(&oid, obj, GIT_OID_SHA1) < 0) { git_error_set(GIT_ERROR_INDEXER, "failed to hash object"); goto on_error; } diff --git a/src/libgit2/iterator.c b/src/libgit2/iterator.c index 8b204b003..a8377f704 100644 --- a/src/libgit2/iterator.c +++ b/src/libgit2/iterator.c @@ -1281,7 +1281,7 @@ static int filesystem_iterator_entry_hash( if (!(error = git_str_joinpath(&fullpath, iter->root, entry->path)) && !(error = git_path_validate_str_length(iter->base.repo, &fullpath))) - error = git_odb_hashfile(&entry->id, fullpath.ptr, GIT_OBJECT_BLOB); + error = git_odb_hashfile(&entry->id, fullpath.ptr, GIT_OBJECT_BLOB, GIT_OID_SHA1); git_str_dispose(&fullpath); return error; diff --git a/src/libgit2/object.c b/src/libgit2/object.c index 61c7b909b..3794e5c23 100644 --- a/src/libgit2/object.c +++ b/src/libgit2/object.c @@ -21,7 +21,6 @@ bool git_object__strict_input_validation = true; -extern int git_odb_hash(git_oid *out, const void *data, size_t len, git_object_t type); size_t git_object__size(git_object_t type); typedef struct { @@ -87,7 +86,7 @@ int git_object__from_raw( GIT_ERROR_CHECK_ALLOC(object); object->cached.flags = GIT_CACHE_STORE_PARSED; object->cached.type = type; - if ((error = git_odb_hash(&object->cached.oid, data, size, type)) < 0) + if ((error = git_odb_hash(&object->cached.oid, data, size, type, GIT_OID_SHA1)) < 0) return error; /* Parse raw object data */ diff --git a/src/libgit2/odb.c b/src/libgit2/odb.c index 3a7d08cbf..787189bc1 100644 --- a/src/libgit2/odb.c +++ b/src/libgit2/odb.c @@ -105,11 +105,12 @@ int git_odb__format_object_header( return 0; } -int git_odb__hashobj(git_oid *id, git_rawobj *obj) +int git_odb__hashobj(git_oid *id, git_rawobj *obj, git_oid_t oid_type) { git_str_vec vec[2]; char header[64]; size_t hdrlen; + git_hash_algorithm_t algorithm; int error; GIT_ASSERT_ARG(id); @@ -120,6 +121,11 @@ int git_odb__hashobj(git_oid *id, git_rawobj *obj) return -1; } + if (!(algorithm = git_oid_algorithm(oid_type))) { + git_error_set(GIT_ERROR_INVALID, "unknown oid type"); + return -1; + } + if (!obj->data && obj->len != 0) { git_error_set(GIT_ERROR_INVALID, "invalid object"); return -1; @@ -134,8 +140,8 @@ int git_odb__hashobj(git_oid *id, git_rawobj *obj) vec[1].data = obj->data; vec[1].len = obj->len; - id->type = GIT_OID_SHA1; - return git_hash_vec(id->id, vec, 2, GIT_HASH_ALGORITHM_SHA1); + id->type = oid_type; + return git_hash_vec(id->id, vec, 2, algorithm); } @@ -196,24 +202,35 @@ void git_odb_object_free(git_odb_object *object) git_cached_obj_decref(object); } -int git_odb__hashfd(git_oid *out, git_file fd, size_t size, git_object_t type) +int git_odb__hashfd( + git_oid *out, + git_file fd, + size_t size, + git_object_t object_type, + git_oid_t oid_type) { size_t hdr_len; char hdr[64], buffer[GIT_BUFSIZE_FILEIO]; git_hash_ctx ctx; + git_hash_algorithm_t algorithm; ssize_t read_len = 0; int error = 0; - if (!git_object_typeisloose(type)) { + if (!git_object_typeisloose(object_type)) { git_error_set(GIT_ERROR_INVALID, "invalid object type for hash"); return -1; } - if ((error = git_hash_ctx_init(&ctx, GIT_HASH_ALGORITHM_SHA1)) < 0) + if (!(algorithm = git_oid_algorithm(oid_type))) { + git_error_set(GIT_ERROR_INVALID, "unknown oid type"); + return -1; + } + + if ((error = git_hash_ctx_init(&ctx, algorithm)) < 0) return error; if ((error = git_odb__format_object_header(&hdr_len, hdr, - sizeof(hdr), size, type)) < 0) + sizeof(hdr), size, object_type)) < 0) goto done; if ((error = git_hash_update(&ctx, hdr, hdr_len)) < 0) @@ -237,7 +254,7 @@ int git_odb__hashfd(git_oid *out, git_file fd, size_t size, git_object_t type) } error = git_hash_final(out->id, &ctx); - out->type = GIT_OID_SHA1; + out->type = oid_type; done: git_hash_ctx_cleanup(&ctx); @@ -245,13 +262,18 @@ done: } int git_odb__hashfd_filtered( - git_oid *out, git_file fd, size_t size, git_object_t type, git_filter_list *fl) + git_oid *out, + git_file fd, + size_t size, + git_object_t object_type, + git_oid_t oid_type, + git_filter_list *fl) { int error; git_str raw = GIT_STR_INIT; if (!fl) - return git_odb__hashfd(out, fd, size, type); + return git_odb__hashfd(out, fd, size, object_type, oid_type); /* size of data is used in header, so we have to read the whole file * into memory to apply filters before beginning to calculate the hash @@ -263,7 +285,7 @@ int git_odb__hashfd_filtered( error = git_filter_list__convert_buf(&post, fl, &raw); if (!error) - error = git_odb_hash(out, post.ptr, post.size, type); + error = git_odb_hash(out, post.ptr, post.size, object_type, oid_type); git_str_dispose(&post); } @@ -271,7 +293,7 @@ int git_odb__hashfd_filtered( return error; } -int git_odb__hashlink(git_oid *out, const char *path) +int git_odb__hashlink(git_oid *out, const char *path, git_oid_t oid_type) { struct stat st; int size; @@ -305,20 +327,24 @@ int git_odb__hashlink(git_oid *out, const char *path) GIT_ASSERT(read_len <= size); link_data[read_len] = '\0'; - result = git_odb_hash(out, link_data, read_len, GIT_OBJECT_BLOB); + result = git_odb_hash(out, link_data, read_len, GIT_OBJECT_BLOB, oid_type); git__free(link_data); } else { int fd = git_futils_open_ro(path); if (fd < 0) return -1; - result = git_odb__hashfd(out, fd, size, GIT_OBJECT_BLOB); + result = git_odb__hashfd(out, fd, size, GIT_OBJECT_BLOB, oid_type); p_close(fd); } return result; } -int git_odb_hashfile(git_oid *out, const char *path, git_object_t type) +int git_odb_hashfile( + git_oid *out, + const char *path, + git_object_t object_type, + git_oid_t oid_type) { uint64_t size; int fd, error = 0; @@ -335,14 +361,19 @@ int git_odb_hashfile(git_oid *out, const char *path, git_object_t type) goto done; } - error = git_odb__hashfd(out, fd, (size_t)size, type); + error = git_odb__hashfd(out, fd, (size_t)size, object_type, oid_type); done: p_close(fd); return error; } -int git_odb_hash(git_oid *id, const void *data, size_t len, git_object_t type) +int git_odb_hash( + git_oid *id, + const void *data, + size_t len, + git_object_t object_type, + git_oid_t oid_type) { git_rawobj raw; @@ -350,9 +381,9 @@ int git_odb_hash(git_oid *id, const void *data, size_t len, git_object_t type) raw.data = (void *)data; raw.len = len; - raw.type = type; + raw.type = object_type; - return git_odb__hashobj(id, &raw); + return git_odb__hashobj(id, &raw, oid_type); } /** @@ -1181,8 +1212,11 @@ int git_odb__read_header_or_object( return error; } -static int odb_read_1(git_odb_object **out, git_odb *db, const git_oid *id, - bool only_refreshed) +static int odb_read_1( + git_odb_object **out, + git_odb *db, + const git_oid *id, + bool only_refreshed) { size_t i; git_rawobj raw; @@ -1226,7 +1260,7 @@ static int odb_read_1(git_odb_object **out, git_odb *db, const git_oid *id, return GIT_ENOTFOUND; if (git_odb__strict_hash_verification) { - if ((error = git_odb_hash(&hashed, raw.data, raw.len, raw.type)) < 0) + if ((error = git_odb_hash(&hashed, raw.data, raw.len, raw.type, GIT_OID_SHA1)) < 0) goto out; if (!git_oid_equal(id, &hashed)) { @@ -1367,7 +1401,7 @@ static int read_prefix_1(git_odb_object **out, git_odb *db, if (git_odb__strict_hash_verification) { git_oid hash; - if ((error = git_odb_hash(&hash, raw.data, raw.len, raw.type)) < 0) + if ((error = git_odb_hash(&hash, raw.data, raw.len, raw.type, GIT_OID_SHA1)) < 0) goto out; if (!git_oid_equal(&found_full_oid, &hash)) { @@ -1466,7 +1500,7 @@ int git_odb_write( GIT_ASSERT_ARG(oid); GIT_ASSERT_ARG(db); - if ((error = git_odb_hash(oid, data, len, type)) < 0) + if ((error = git_odb_hash(oid, data, len, type, GIT_OID_SHA1)) < 0) return error; if (git_oid_is_zero(oid)) @@ -1568,7 +1602,7 @@ int git_odb_open_wstream( GIT_ERROR_CHECK_ALLOC(ctx); if ((error = git_hash_ctx_init(ctx, GIT_HASH_ALGORITHM_SHA1)) < 0 || - (error = hash_header(ctx, size, type)) < 0) + (error = hash_header(ctx, size, type)) < 0) goto done; (*stream)->hash_ctx = ctx; @@ -1790,10 +1824,11 @@ int git_odb_refresh(struct git_odb *db) int git_odb__error_mismatch(const git_oid *expected, const git_oid *actual) { - char expected_oid[GIT_OID_SHA1_HEXSIZE + 1], actual_oid[GIT_OID_SHA1_HEXSIZE + 1]; + char expected_oid[GIT_OID_MAX_HEXSIZE + 1], + actual_oid[GIT_OID_MAX_HEXSIZE + 1]; - git_oid_tostr(expected_oid, sizeof(expected_oid), expected); - git_oid_tostr(actual_oid, sizeof(actual_oid), actual); + git_oid_tostr(expected_oid, git_oid_hexsize(expected->type) + 1, expected); + git_oid_tostr(actual_oid, git_oid_hexsize(actual->type) + 1, actual); git_error_set(GIT_ERROR_ODB, "object hash mismatch - expected %s but got %s", expected_oid, actual_oid); @@ -1805,7 +1840,7 @@ int git_odb__error_notfound( const char *message, const git_oid *oid, size_t oid_len) { if (oid != NULL) { - char oid_str[GIT_OID_SHA1_HEXSIZE + 1]; + char oid_str[GIT_OID_MAX_HEXSIZE + 1]; git_oid_tostr(oid_str, oid_len+1, oid); git_error_set(GIT_ERROR_ODB, "object not found - %s (%.*s)", message, (int) oid_len, oid_str); @@ -1823,7 +1858,7 @@ static int error_null_oid(int error, const char *message) int git_odb__error_ambiguous(const char *message) { - git_error_set(GIT_ERROR_ODB, "ambiguous SHA1 prefix - %s", message); + git_error_set(GIT_ERROR_ODB, "ambiguous OID prefix - %s", message); return GIT_EAMBIGUOUS; } diff --git a/src/libgit2/odb.h b/src/libgit2/odb.h index 5aa4cc84a..c85fa671b 100644 --- a/src/libgit2/odb.h +++ b/src/libgit2/odb.h @@ -72,7 +72,7 @@ int git_odb__add_default_backends( * Hash a git_rawobj internally. * The `git_rawobj` is supposed to be previously initialized */ -int git_odb__hashobj(git_oid *id, git_rawobj *obj); +int git_odb__hashobj(git_oid *id, git_rawobj *obj, git_oid_t oid_type); /* * Format the object header such as it would appear in the on-disk object @@ -89,14 +89,24 @@ int git_odb__format_object_header(size_t *out_len, char *hdr, size_t hdr_size, g * The fd is never closed, not even on error. It must be opened and closed * by the caller */ -int git_odb__hashfd(git_oid *out, git_file fd, size_t size, git_object_t type); +int git_odb__hashfd( + git_oid *out, + git_file fd, + size_t size, + git_object_t object_type, + git_oid_t oid_type); /* * Hash an open file descriptor applying an array of filters * Acts just like git_odb__hashfd with the addition of filters... */ int git_odb__hashfd_filtered( - git_oid *out, git_file fd, size_t len, git_object_t type, git_filter_list *fl); + git_oid *out, + git_file fd, + size_t len, + git_object_t object_type, + git_oid_t oid_type, + git_filter_list *fl); /* * Hash a `path`, assuming it could be a POSIX symlink: if the path is a @@ -106,7 +116,7 @@ int git_odb__hashfd_filtered( * The hash type for this call is always `GIT_OBJECT_BLOB` because * symlinks may only point to blobs. */ -int git_odb__hashlink(git_oid *out, const char *path); +int git_odb__hashlink(git_oid *out, const char *path, git_oid_t oid_type); /** * Generate a GIT_EMISMATCH error for the ODB. diff --git a/src/libgit2/reader.c b/src/libgit2/reader.c index ba9775240..0ff9c89c3 100644 --- a/src/libgit2/reader.c +++ b/src/libgit2/reader.c @@ -125,7 +125,7 @@ static int workdir_reader_read( goto done; if (out_id || reader->index) { - if ((error = git_odb_hash(&id, out->ptr, out->size, GIT_OBJECT_BLOB)) < 0) + if ((error = git_odb_hash(&id, out->ptr, out->size, GIT_OBJECT_BLOB, GIT_OID_SHA1)) < 0) goto done; } diff --git a/src/libgit2/repository.c b/src/libgit2/repository.c index 1312ccce0..adff425e6 100644 --- a/src/libgit2/repository.c +++ b/src/libgit2/repository.c @@ -2986,7 +2986,7 @@ int git_repository_hashfile( goto cleanup; } - error = git_odb__hashfd_filtered(out, fd, (size_t)len, type, fl); + error = git_odb__hashfd_filtered(out, fd, (size_t)len, type, GIT_OID_SHA1, fl); cleanup: if (fd >= 0) diff --git a/tests/libgit2/checkout/binaryunicode.c b/tests/libgit2/checkout/binaryunicode.c index 255b6e06d..ea2f527e9 100644 --- a/tests/libgit2/checkout/binaryunicode.c +++ b/tests/libgit2/checkout/binaryunicode.c @@ -36,12 +36,12 @@ static void execute_test(void) /* Verify that the lenna.jpg file was checked out correctly */ cl_git_pass(git_oid_fromstr(&check, "8ab005d890fe53f65eda14b23672f60d9f4ec5a1", GIT_OID_SHA1)); - cl_git_pass(git_odb_hashfile(&oid, "binaryunicode/lenna.jpg", GIT_OBJECT_BLOB)); + cl_git_pass(git_odb_hashfile(&oid, "binaryunicode/lenna.jpg", GIT_OBJECT_BLOB, GIT_OID_SHA1)); cl_assert_equal_oid(&oid, &check); /* Verify that the text file was checked out correctly */ cl_git_pass(git_oid_fromstr(&check, "965b223880dd4249e2c66a0cc0b4cffe1dc40f5a", GIT_OID_SHA1)); - cl_git_pass(git_odb_hashfile(&oid, "binaryunicode/utf16_withbom_noeol_crlf.txt", GIT_OBJECT_BLOB)); + cl_git_pass(git_odb_hashfile(&oid, "binaryunicode/utf16_withbom_noeol_crlf.txt", GIT_OBJECT_BLOB, GIT_OID_SHA1)); cl_assert_equal_oid(&oid, &check); } diff --git a/tests/libgit2/object/raw/hash.c b/tests/libgit2/object/raw/hash.c index 28bfb1db8..e0d3d95ea 100644 --- a/tests/libgit2/object/raw/hash.c +++ b/tests/libgit2/object/raw/hash.c @@ -8,11 +8,11 @@ static void hash_object_pass(git_oid *oid, git_rawobj *obj) { - cl_git_pass(git_odb_hash(oid, obj->data, obj->len, obj->type)); + cl_git_pass(git_odb_hash(oid, obj->data, obj->len, obj->type, GIT_OID_SHA1)); } static void hash_object_fail(git_oid *oid, git_rawobj *obj) { - cl_git_fail(git_odb_hash(oid, obj->data, obj->len, obj->type)); + cl_git_fail(git_odb_hash(oid, obj->data, obj->len, obj->type, GIT_OID_SHA1)); } static char *hello_id = "22596363b3de40b06f981fb85d82312e8c0ed511"; diff --git a/tests/libgit2/repo/hashfile.c b/tests/libgit2/repo/hashfile.c index e23bb77f9..f83543974 100644 --- a/tests/libgit2/repo/hashfile.c +++ b/tests/libgit2/repo/hashfile.c @@ -20,19 +20,19 @@ void test_repo_hashfile__simple(void) git_str full = GIT_STR_INIT; /* hash with repo relative path */ - cl_git_pass(git_odb_hashfile(&a, "status/current_file", GIT_OBJECT_BLOB)); + cl_git_pass(git_odb_hashfile(&a, "status/current_file", GIT_OBJECT_BLOB, GIT_OID_SHA1)); cl_git_pass(git_repository_hashfile(&b, _repo, "current_file", GIT_OBJECT_BLOB, NULL)); cl_assert_equal_oid(&a, &b); cl_git_pass(git_str_joinpath(&full, git_repository_workdir(_repo), "current_file")); /* hash with full path */ - cl_git_pass(git_odb_hashfile(&a, full.ptr, GIT_OBJECT_BLOB)); + cl_git_pass(git_odb_hashfile(&a, full.ptr, GIT_OBJECT_BLOB, GIT_OID_SHA1)); cl_git_pass(git_repository_hashfile(&b, _repo, full.ptr, GIT_OBJECT_BLOB, NULL)); cl_assert_equal_oid(&a, &b); /* hash with invalid type */ - cl_git_fail(git_odb_hashfile(&a, full.ptr, GIT_OBJECT_ANY)); + cl_git_fail(git_odb_hashfile(&a, full.ptr, GIT_OBJECT_ANY, GIT_OID_SHA1)); cl_git_fail(git_repository_hashfile(&b, _repo, full.ptr, GIT_OBJECT_OFS_DELTA, NULL)); git_str_dispose(&full); @@ -59,64 +59,64 @@ void test_repo_hashfile__filtered_in_workdir(void) cl_git_mkfile("status/testfile.bin", "other\r\nstuff\r\n"); /* not equal hashes because of filtering */ - cl_git_pass(git_odb_hashfile(&a, "status/testfile.txt", GIT_OBJECT_BLOB)); + cl_git_pass(git_odb_hashfile(&a, "status/testfile.txt", GIT_OBJECT_BLOB, GIT_OID_SHA1)); cl_git_pass(git_repository_hashfile(&b, _repo, "testfile.txt", GIT_OBJECT_BLOB, NULL)); cl_assert(git_oid_cmp(&a, &b)); /* not equal hashes because of filtering when specified by absolute path */ - cl_git_pass(git_odb_hashfile(&a, "status/testfile.txt", GIT_OBJECT_BLOB)); + cl_git_pass(git_odb_hashfile(&a, "status/testfile.txt", GIT_OBJECT_BLOB, GIT_OID_SHA1)); cl_git_pass(git_repository_hashfile(&b, _repo, txt.ptr, GIT_OBJECT_BLOB, NULL)); cl_assert(git_oid_cmp(&a, &b)); /* equal hashes because filter is binary */ - cl_git_pass(git_odb_hashfile(&a, "status/testfile.bin", GIT_OBJECT_BLOB)); + cl_git_pass(git_odb_hashfile(&a, "status/testfile.bin", GIT_OBJECT_BLOB, GIT_OID_SHA1)); cl_git_pass(git_repository_hashfile(&b, _repo, "testfile.bin", GIT_OBJECT_BLOB, NULL)); cl_assert_equal_oid(&a, &b); /* equal hashes because filter is binary when specified by absolute path */ - cl_git_pass(git_odb_hashfile(&a, "status/testfile.bin", GIT_OBJECT_BLOB)); + cl_git_pass(git_odb_hashfile(&a, "status/testfile.bin", GIT_OBJECT_BLOB, GIT_OID_SHA1)); cl_git_pass(git_repository_hashfile(&b, _repo, bin.ptr, GIT_OBJECT_BLOB, NULL)); cl_assert_equal_oid(&a, &b); /* equal hashes when 'as_file' points to binary filtering */ - cl_git_pass(git_odb_hashfile(&a, "status/testfile.txt", GIT_OBJECT_BLOB)); + cl_git_pass(git_odb_hashfile(&a, "status/testfile.txt", GIT_OBJECT_BLOB, GIT_OID_SHA1)); cl_git_pass(git_repository_hashfile(&b, _repo, "testfile.txt", GIT_OBJECT_BLOB, "foo.bin")); cl_assert_equal_oid(&a, &b); /* equal hashes when 'as_file' points to binary filtering (absolute path) */ - cl_git_pass(git_odb_hashfile(&a, "status/testfile.txt", GIT_OBJECT_BLOB)); + cl_git_pass(git_odb_hashfile(&a, "status/testfile.txt", GIT_OBJECT_BLOB, GIT_OID_SHA1)); cl_git_pass(git_repository_hashfile(&b, _repo, txt.ptr, GIT_OBJECT_BLOB, "foo.bin")); cl_assert_equal_oid(&a, &b); /* not equal hashes when 'as_file' points to text filtering */ - cl_git_pass(git_odb_hashfile(&a, "status/testfile.bin", GIT_OBJECT_BLOB)); + cl_git_pass(git_odb_hashfile(&a, "status/testfile.bin", GIT_OBJECT_BLOB, GIT_OID_SHA1)); cl_git_pass(git_repository_hashfile(&b, _repo, "testfile.bin", GIT_OBJECT_BLOB, "foo.txt")); cl_assert(git_oid_cmp(&a, &b)); /* not equal hashes when 'as_file' points to text filtering */ - cl_git_pass(git_odb_hashfile(&a, "status/testfile.bin", GIT_OBJECT_BLOB)); + cl_git_pass(git_odb_hashfile(&a, "status/testfile.bin", GIT_OBJECT_BLOB, GIT_OID_SHA1)); cl_git_pass(git_repository_hashfile(&b, _repo, bin.ptr, GIT_OBJECT_BLOB, "foo.txt")); cl_assert(git_oid_cmp(&a, &b)); /* equal hashes when 'as_file' is empty and turns off filtering */ - cl_git_pass(git_odb_hashfile(&a, "status/testfile.txt", GIT_OBJECT_BLOB)); + cl_git_pass(git_odb_hashfile(&a, "status/testfile.txt", GIT_OBJECT_BLOB, GIT_OID_SHA1)); cl_git_pass(git_repository_hashfile(&b, _repo, "testfile.txt", GIT_OBJECT_BLOB, "")); cl_assert_equal_oid(&a, &b); - cl_git_pass(git_odb_hashfile(&a, "status/testfile.bin", GIT_OBJECT_BLOB)); + cl_git_pass(git_odb_hashfile(&a, "status/testfile.bin", GIT_OBJECT_BLOB, GIT_OID_SHA1)); cl_git_pass(git_repository_hashfile(&b, _repo, "testfile.bin", GIT_OBJECT_BLOB, "")); cl_assert_equal_oid(&a, &b); - cl_git_pass(git_odb_hashfile(&a, "status/testfile.txt", GIT_OBJECT_BLOB)); + cl_git_pass(git_odb_hashfile(&a, "status/testfile.txt", GIT_OBJECT_BLOB, GIT_OID_SHA1)); cl_git_pass(git_repository_hashfile(&b, _repo, txt.ptr, GIT_OBJECT_BLOB, "")); cl_assert_equal_oid(&a, &b); - cl_git_pass(git_odb_hashfile(&a, "status/testfile.bin", GIT_OBJECT_BLOB)); + cl_git_pass(git_odb_hashfile(&a, "status/testfile.bin", GIT_OBJECT_BLOB, GIT_OID_SHA1)); cl_git_pass(git_repository_hashfile(&b, _repo, bin.ptr, GIT_OBJECT_BLOB, "")); cl_assert_equal_oid(&a, &b); /* some hash type failures */ - cl_git_fail(git_odb_hashfile(&a, "status/testfile.txt", 0)); + cl_git_fail(git_odb_hashfile(&a, "status/testfile.txt", 0, GIT_OID_SHA1)); cl_git_fail(git_repository_hashfile(&b, _repo, "testfile.txt", GIT_OBJECT_ANY, NULL)); git_str_dispose(&txt); @@ -144,12 +144,12 @@ void test_repo_hashfile__filtered_outside_workdir(void) cl_git_mkfile("absolute/testfile.bin", "other\r\nstuff\r\n"); /* not equal hashes because of filtering */ - cl_git_pass(git_odb_hashfile(&a, "absolute/testfile.txt", GIT_OBJECT_BLOB)); + cl_git_pass(git_odb_hashfile(&a, "absolute/testfile.txt", GIT_OBJECT_BLOB, GIT_OID_SHA1)); cl_git_pass(git_repository_hashfile(&b, _repo, txt.ptr, GIT_OBJECT_BLOB, "testfile.txt")); cl_assert(git_oid_cmp(&a, &b)); /* equal hashes because filter is binary */ - cl_git_pass(git_odb_hashfile(&a, "absolute/testfile.bin", GIT_OBJECT_BLOB)); + cl_git_pass(git_odb_hashfile(&a, "absolute/testfile.bin", GIT_OBJECT_BLOB, GIT_OID_SHA1)); cl_git_pass(git_repository_hashfile(&b, _repo, bin.ptr, GIT_OBJECT_BLOB, "testfile.bin")); cl_assert_equal_oid(&a, &b); @@ -157,11 +157,11 @@ void test_repo_hashfile__filtered_outside_workdir(void) * equal hashes because no filtering occurs for absolute paths outside the working * directory unless as_path is specified */ - cl_git_pass(git_odb_hashfile(&a, "absolute/testfile.txt", GIT_OBJECT_BLOB)); + cl_git_pass(git_odb_hashfile(&a, "absolute/testfile.txt", GIT_OBJECT_BLOB, GIT_OID_SHA1)); cl_git_pass(git_repository_hashfile(&b, _repo, txt.ptr, GIT_OBJECT_BLOB, NULL)); cl_assert_equal_oid(&a, &b); - cl_git_pass(git_odb_hashfile(&a, "absolute/testfile.bin", GIT_OBJECT_BLOB)); + cl_git_pass(git_odb_hashfile(&a, "absolute/testfile.bin", GIT_OBJECT_BLOB, GIT_OID_SHA1)); cl_git_pass(git_repository_hashfile(&b, _repo, bin.ptr, GIT_OBJECT_BLOB, NULL)); cl_assert_equal_oid(&a, &b); diff --git a/tests/libgit2/status/single.c b/tests/libgit2/status/single.c index a95d3d09c..dfba8f4e0 100644 --- a/tests/libgit2/status/single.c +++ b/tests/libgit2/status/single.c @@ -21,7 +21,7 @@ void test_status_single__hash_single_file(void) cl_git_mkfile(file_name, file_contents); cl_set_cleanup(&cleanup__remove_file, (void *)file_name); - cl_git_pass(git_odb_hashfile(&actual_id, file_name, GIT_OBJECT_BLOB)); + cl_git_pass(git_odb_hashfile(&actual_id, file_name, GIT_OBJECT_BLOB, GIT_OID_SHA1)); cl_assert_equal_oid(&expected_id, &actual_id); } @@ -39,7 +39,7 @@ void test_status_single__hash_single_empty_file(void) cl_git_mkfile(file_name, file_contents); cl_set_cleanup(&cleanup__remove_file, (void *)file_name); - cl_git_pass(git_odb_hashfile(&actual_id, file_name, GIT_OBJECT_BLOB)); + cl_git_pass(git_odb_hashfile(&actual_id, file_name, GIT_OBJECT_BLOB, GIT_OID_SHA1)); cl_assert_equal_oid(&expected_id, &actual_id); } |