diff options
Diffstat (limited to 'src')
36 files changed, 216 insertions, 108 deletions
diff --git a/src/libgit2/attr_file.c b/src/libgit2/attr_file.c index 0eb881a9b..afa8ec7b3 100644 --- a/src/libgit2/attr_file.c +++ b/src/libgit2/attr_file.c @@ -135,7 +135,7 @@ int git_attr_file__load( break; case GIT_ATTR_FILE_SOURCE_INDEX: { if ((error = attr_file_oid_from_index(&id, repo, entry->path)) < 0 || - (error = git_blob_lookup(&blob, repo, &id)) < 0) + (error = git_blob_lookup(&blob, repo, &id)) < 0) return error; /* Do not assume that data straight from the ODB is NULL-terminated; diff --git a/src/libgit2/blame.c b/src/libgit2/blame.c index a6ab43efd..b70cd615e 100644 --- a/src/libgit2/blame.c +++ b/src/libgit2/blame.c @@ -72,6 +72,8 @@ static git_blame_hunk *new_hunk( hunk->final_start_line_number = start; hunk->orig_start_line_number = orig_start; hunk->orig_path = path ? git__strdup(path) : NULL; + git_oid_clear(&hunk->orig_commit_id, GIT_OID_SHA1); + git_oid_clear(&hunk->final_commit_id, GIT_OID_SHA1); return hunk; } diff --git a/src/libgit2/commit.c b/src/libgit2/commit.c index 6dc1bbca6..114ae6fc9 100644 --- a/src/libgit2/commit.c +++ b/src/libgit2/commit.c @@ -411,7 +411,8 @@ static int commit_parse(git_commit *commit, const char *data, size_t size, unsig /* The tree is always the first field */ if (!(flags & GIT_COMMIT_PARSE_QUICK)) { if (git_object__parse_oid_header(&commit->tree_id, - &buffer, buffer_end, "tree ") < 0) + &buffer, buffer_end, "tree ", + GIT_OID_SHA1) < 0) goto bad_buffer; } else { size_t tree_len = strlen("tree ") + GIT_OID_SHA1_HEXSIZE + 1; @@ -425,7 +426,8 @@ static int commit_parse(git_commit *commit, const char *data, size_t size, unsig */ while (git_object__parse_oid_header(&parent_id, - &buffer, buffer_end, "parent ") == 0) { + &buffer, buffer_end, "parent ", + GIT_OID_SHA1) == 0) { git_oid *new_id = git_array_alloc(commit->parent_ids); GIT_ERROR_CHECK_ALLOC(new_id); diff --git a/src/libgit2/commit_graph.c b/src/libgit2/commit_graph.c index 7e98ffb27..2edf51a58 100644 --- a/src/libgit2/commit_graph.c +++ b/src/libgit2/commit_graph.c @@ -150,7 +150,7 @@ static int commit_graph_parse_oid_lookup( file->oid_lookup = oid = (unsigned char *)(data + chunk_oid_lookup->offset); prev_oid = zero_oid; for (i = 0; i < file->num_commits; ++i, oid += GIT_OID_SHA1_SIZE) { - if (git_oid_raw_cmp(prev_oid, oid) >= 0) + if (git_oid_raw_cmp(prev_oid, oid, GIT_OID_SHA1_SIZE) >= 0) return commit_graph_error("OID Lookup index is non-monotonic"); prev_oid = oid; } @@ -437,7 +437,7 @@ static int git_commit_graph_entry_get_byindex( } commit_data = file->commit_data + pos * (GIT_OID_SHA1_SIZE + 4 * sizeof(uint32_t)); - git_oid_fromraw(&e->tree_oid, commit_data); + git_oid_fromraw(&e->tree_oid, commit_data, GIT_OID_SHA1); e->parent_indices[0] = ntohl(*((uint32_t *)(commit_data + GIT_OID_SHA1_SIZE))); e->parent_indices[1] = ntohl( *((uint32_t *)(commit_data + GIT_OID_SHA1_SIZE + sizeof(uint32_t)))); @@ -471,7 +471,7 @@ static int git_commit_graph_entry_get_byindex( } } - git_oid_fromraw(&e->sha1, &file->oid_lookup[pos * GIT_OID_SHA1_SIZE]); + git_oid_fromraw(&e->sha1, &file->oid_lookup[pos * GIT_OID_SHA1_SIZE], GIT_OID_SHA1); return 0; } diff --git a/src/libgit2/diff.c b/src/libgit2/diff.c index f593f7336..91931e75b 100644 --- a/src/libgit2/diff.c +++ b/src/libgit2/diff.c @@ -381,6 +381,7 @@ int git_diff_patchid(git_oid *out, git_diff *diff, git_diff_patchid_options *opt if ((error = (flush_hunk(&args.result, &args.ctx))) < 0) goto out; + args.result.type = GIT_OID_SHA1; git_oid_cpy(out, &args.result); out: diff --git a/src/libgit2/diff_file.c b/src/libgit2/diff_file.c index 8006b31df..397165577 100644 --- a/src/libgit2/diff_file.c +++ b/src/libgit2/diff_file.c @@ -144,6 +144,7 @@ int git_diff_file_content__init_from_src( if (!src->blob && !src->buf) { fc->flags |= GIT_DIFF_FLAG__NO_DATA; + git_oid_clear(&fc->file->id, GIT_OID_SHA1); } else { fc->flags |= GIT_DIFF_FLAG__LOADED; fc->file->flags |= GIT_DIFF_FLAG_VALID_ID; diff --git a/src/libgit2/diff_generate.c b/src/libgit2/diff_generate.c index 16efbc7f6..d22c55701 100644 --- a/src/libgit2/diff_generate.c +++ b/src/libgit2/diff_generate.c @@ -61,6 +61,9 @@ static git_diff_delta *diff_delta__alloc( } delta->status = status; + git_oid_clear(&delta->old_file.id, GIT_OID_SHA1); + git_oid_clear(&delta->new_file.id, GIT_OID_SHA1); + return delta; } @@ -188,11 +191,13 @@ static int diff_delta__from_one( delta->old_file.size = entry->file_size; delta->old_file.flags |= GIT_DIFF_FLAG_EXISTS; git_oid_cpy(&delta->old_file.id, &entry->id); + git_oid_clear(&delta->new_file.id, GIT_OID_SHA1); delta->old_file.id_abbrev = GIT_OID_SHA1_HEXSIZE; } else /* ADDED, IGNORED, UNTRACKED */ { delta->new_file.mode = entry->mode; delta->new_file.size = entry->file_size; delta->new_file.flags |= GIT_DIFF_FLAG_EXISTS; + git_oid_clear(&delta->old_file.id, GIT_OID_SHA1); git_oid_cpy(&delta->new_file.id, &entry->id); delta->new_file.id_abbrev = GIT_OID_SHA1_HEXSIZE; } @@ -598,6 +603,7 @@ int git_diff__oid_for_file( entry.mode = mode; entry.file_size = (uint32_t)size; entry.path = (char *)path; + git_oid_clear(&entry.id, GIT_OID_SHA1); return git_diff__oid_for_entry(out, diff, &entry, mode, NULL); } @@ -618,7 +624,7 @@ int git_diff__oid_for_entry( GIT_ASSERT(d->type == GIT_DIFF_TYPE_GENERATED); diff = (git_diff_generated *)d; - memset(out, 0, sizeof(*out)); + git_oid_clear(out, GIT_OID_SHA1); if (git_repository_workdir_path(&full_path, diff->base.repo, entry.path) < 0) return -1; @@ -778,7 +784,7 @@ static int maybe_modified( git_diff_generated *diff, diff_in_progress *info) { - git_oid noid; + git_oid noid = GIT_OID_SHA1_ZERO; git_delta_t status = GIT_DELTA_MODIFIED; const git_index_entry *oitem = info->oitem; const git_index_entry *nitem = info->nitem; @@ -792,8 +798,6 @@ static int maybe_modified( if (!diff_pathspec_match(&matched_pathspec, diff, oitem)) return 0; - memset(&noid, 0, sizeof(noid)); - /* on platforms with no symlinks, preserve mode of existing symlinks */ if (S_ISLNK(omode) && S_ISREG(nmode) && new_is_workdir && !(diff->diffcaps & GIT_DIFFCAPS_HAS_SYMLINKS)) diff --git a/src/libgit2/diff_tform.c b/src/libgit2/diff_tform.c index 913d649b0..8c0c1b7fc 100644 --- a/src/libgit2/diff_tform.c +++ b/src/libgit2/diff_tform.c @@ -364,6 +364,7 @@ static int insert_delete_side_of_split( memset(&deleted->new_file, 0, sizeof(deleted->new_file)); deleted->new_file.path = deleted->old_file.path; deleted->new_file.flags |= GIT_DIFF_FLAG_VALID_ID; + git_oid_clear(&deleted->new_file.id, GIT_OID_SHA1); return git_vector_insert(onto, deleted); } @@ -397,6 +398,7 @@ static int apply_splits_and_deletes( memset(&delta->old_file, 0, sizeof(delta->old_file)); delta->old_file.path = delta->new_file.path; delta->old_file.flags |= GIT_DIFF_FLAG_VALID_ID; + git_oid_clear(&delta->old_file.id, GIT_OID_SHA1); } /* clean up delta before inserting into new list */ @@ -995,6 +997,7 @@ find_best_matches: memset(&src->new_file, 0, sizeof(src->new_file)); src->new_file.path = src->old_file.path; src->new_file.flags |= GIT_DIFF_FLAG_VALID_ID; + git_oid_clear(&src->new_file.id, GIT_OID_SHA1); num_updates++; @@ -1020,6 +1023,7 @@ find_best_matches: memset(&src->old_file, 0, sizeof(src->old_file)); src->old_file.path = src->new_file.path; src->old_file.flags |= GIT_DIFF_FLAG_VALID_ID; + git_oid_clear(&src->old_file.id, GIT_OID_SHA1); src->flags &= ~GIT_DIFF_FLAG__TO_SPLIT; num_rewrites--; diff --git a/src/libgit2/fetch.c b/src/libgit2/fetch.c index e9f30d9bc..c27857078 100644 --- a/src/libgit2/fetch.c +++ b/src/libgit2/fetch.c @@ -75,7 +75,7 @@ static int maybe_want_oid(git_remote *remote, git_refspec *spec) oid_head = git__calloc(1, sizeof(git_remote_head)); GIT_ERROR_CHECK_ALLOC(oid_head); - git_oid_fromstr(&oid_head->oid, spec->src); + git_oid_fromstr(&oid_head->oid, spec->src, GIT_OID_SHA1); if (spec->dst) { oid_head->name = git__strdup(spec->dst); @@ -140,7 +140,7 @@ static int filter_wants(git_remote *remote, const git_fetch_options *opts) /* Handle explicitly specified OID specs */ git_vector_foreach(&remote->active_refspecs, i, spec) { - if (!git_oid__is_hexstr(spec->src)) + if (!git_oid__is_hexstr(spec->src, GIT_OID_SHA1)) continue; if (!(remote_caps & oid_mask)) { diff --git a/src/libgit2/fetchhead.c b/src/libgit2/fetchhead.c index 146d891ae..117d7a01d 100644 --- a/src/libgit2/fetchhead.c +++ b/src/libgit2/fetchhead.c @@ -202,7 +202,7 @@ static int fetchhead_ref_parse( return -1; } - if (git_oid_fromstr(oid, oid_str) < 0) { + if (git_oid_fromstr(oid, oid_str, GIT_OID_SHA1) < 0) { const git_error *oid_err = git_error_last(); const char *err_msg = oid_err ? oid_err->message : "invalid object ID"; diff --git a/src/libgit2/index.c b/src/libgit2/index.c index 977820a4e..91d74a01e 100644 --- a/src/libgit2/index.c +++ b/src/libgit2/index.c @@ -2354,14 +2354,16 @@ static int read_reuc(git_index *index, const char *buffer, size_t size) for (i = 0; i < 3; i++) { if (!lost->mode[i]) continue; - if (size < 20) { + if (size < GIT_OID_SHA1_SIZE) { index_entry_reuc_free(lost); return index_error_invalid("reading reuc entry oid"); } - git_oid_fromraw(&lost->oid[i], (const unsigned char *) buffer); - size -= 20; - buffer += 20; + if (git_oid_fromraw(&lost->oid[i], (const unsigned char *) buffer, GIT_OID_SHA1) < 0) + return -1; + + size -= GIT_OID_SHA1_SIZE; + buffer += GIT_OID_SHA1_SIZE; } /* entry was read successfully - insert into reuc vector */ @@ -2482,7 +2484,7 @@ static int read_entry( entry.file_size = ntohl(source.file_size); entry.flags = ntohs(source.flags); - if (git_oid_fromraw(&entry.id, source.oid) < 0) + if (git_oid_fromraw(&entry.id, source.oid, GIT_OID_SHA1) < 0) return -1; if (entry.flags & GIT_INDEX_ENTRY_EXTENDED) { @@ -2805,7 +2807,7 @@ static int write_disk_entry(git_filebuf *file, git_index_entry *entry, const cha ondisk.uid = htonl(entry->uid); ondisk.gid = htonl(entry->gid); ondisk.file_size = htonl((uint32_t)entry->file_size); - git_oid_raw_cpy(ondisk.oid, entry->id.id); + git_oid_raw_cpy(ondisk.oid, entry->id.id, GIT_OID_SHA1_SIZE); ondisk.flags = htons(entry->flags); if (entry->flags & GIT_INDEX_ENTRY_EXTENDED) { diff --git a/src/libgit2/indexer.c b/src/libgit2/indexer.c index f3d701fdd..e7ea77ee9 100644 --- a/src/libgit2/indexer.c +++ b/src/libgit2/indexer.c @@ -444,6 +444,8 @@ static int store_object(git_indexer *idx) git__free(pentry); goto on_error; } + oid.type = GIT_OID_SHA1; + entry_size = idx->off - entry_start; if (entry_start > UINT31_MAX) { entry->offset = UINT32_MAX; @@ -1046,7 +1048,7 @@ static int fix_thin_pack(git_indexer *idx, git_indexer_progress *stats) return -1; } - git_oid_fromraw(&base, base_info); + git_oid_fromraw(&base, base_info, GIT_OID_SHA1); git_mwindow_close(&w); if (has_entry(idx, &base)) diff --git a/src/libgit2/iterator.c b/src/libgit2/iterator.c index 6b127afd3..8b204b003 100644 --- a/src/libgit2/iterator.c +++ b/src/libgit2/iterator.c @@ -1529,6 +1529,8 @@ static void filesystem_iterator_set_current( if (iter->base.flags & GIT_ITERATOR_INCLUDE_HASH) git_oid_cpy(&iter->entry.id, &entry->id); + else + git_oid_clear(&iter->entry.id, GIT_OID_SHA1); iter->entry.path = entry->path; diff --git a/src/libgit2/merge.c b/src/libgit2/merge.c index e4db2629c..06c52a67c 100644 --- a/src/libgit2/merge.c +++ b/src/libgit2/merge.c @@ -617,7 +617,7 @@ int git_repository_mergehead_foreach( goto cleanup; } - if ((error = git_oid_fromstr(&oid, line)) < 0) + if ((error = git_oid_fromstr(&oid, line, GIT_OID_SHA1)) < 0) goto cleanup; if ((error = cb(&oid, payload)) != 0) { diff --git a/src/libgit2/midx.c b/src/libgit2/midx.c index 86803fa64..8c0b8df40 100644 --- a/src/libgit2/midx.c +++ b/src/libgit2/midx.c @@ -127,7 +127,7 @@ static int midx_parse_oid_lookup( idx->oid_lookup = oid = (unsigned char *)(data + chunk_oid_lookup->offset); prev_oid = zero_oid; for (i = 0; i < idx->num_objects; ++i, oid += GIT_OID_SHA1_SIZE) { - if (git_oid_raw_cmp(prev_oid, oid) >= 0) + if (git_oid_raw_cmp(prev_oid, oid, GIT_OID_SHA1_SIZE) >= 0) return midx_error("OID Lookup index is non-monotonic"); prev_oid = oid; } @@ -443,7 +443,7 @@ int git_midx_entry_find( return midx_error("invalid index into the packfile names table"); e->pack_index = pack_index; e->offset = offset; - git_oid_fromraw(&e->sha1, current); + git_oid_fromraw(&e->sha1, current, GIT_OID_SHA1); return 0; } @@ -459,7 +459,7 @@ int git_midx_foreach_entry( GIT_ASSERT_ARG(idx); for (i = 0; i < idx->num_objects; ++i) { - if ((error = git_oid_fromraw(&oid, &idx->oid_lookup[i * GIT_OID_SHA1_SIZE])) < 0) + if ((error = git_oid_fromraw(&oid, &idx->oid_lookup[i * GIT_OID_SHA1_SIZE], GIT_OID_SHA1)) < 0) return error; if ((error = cb(&oid, data)) != 0) diff --git a/src/libgit2/notes.c b/src/libgit2/notes.c index a154d96c7..08395aef5 100644 --- a/src/libgit2/notes.c +++ b/src/libgit2/notes.c @@ -703,7 +703,7 @@ static int process_entry_path( goto cleanup; } - error = git_oid_fromstr(annotated_object_id, buf.ptr); + error = git_oid_fromstr(annotated_object_id, buf.ptr, GIT_OID_SHA1); cleanup: git_str_dispose(&buf); diff --git a/src/libgit2/object.c b/src/libgit2/object.c index a03702658..61c7b909b 100644 --- a/src/libgit2/object.c +++ b/src/libgit2/object.c @@ -521,6 +521,7 @@ static int git_object__short_id(git_str *out, const git_object *obj) memcpy(&id.id, &obj->cached.oid.id, (len + 1) / 2); if (len & 1) id.id[len / 2] &= 0xf0; + id.type = GIT_OID_SHA1; error = git_odb_exists_prefix(NULL, odb, &id, len); if (error != GIT_EAMBIGUOUS) @@ -605,7 +606,8 @@ int git_object__parse_oid_header( git_oid *oid, const char **buffer_out, const char *buffer_end, - const char *header) + const char *header, + git_oid_t oid_type) { const size_t sha_len = GIT_OID_SHA1_HEXSIZE; const size_t header_len = strlen(header); @@ -621,7 +623,7 @@ int git_object__parse_oid_header( if (buffer[header_len + sha_len] != '\n') return -1; - if (git_oid_fromstr(oid, buffer + header_len) < 0) + if (git_oid_fromstr(oid, buffer + header_len, oid_type) < 0) return -1; *buffer_out = buffer + (header_len + sha_len + 1); @@ -634,11 +636,17 @@ int git_object__write_oid_header( const char *header, const git_oid *oid) { - char hex_oid[GIT_OID_SHA1_HEXSIZE]; + size_t hex_size = git_oid_hexsize(oid->type); + char hex_oid[GIT_OID_MAX_HEXSIZE]; + + if (!hex_size) { + git_error_set(GIT_ERROR_INVALID, "unknown type"); + return -1; + } git_oid_fmt(hex_oid, oid); git_str_puts(buf, header); - git_str_put(buf, hex_oid, GIT_OID_SHA1_HEXSIZE); + git_str_put(buf, hex_oid, hex_size); git_str_putc(buf, '\n'); return git_str_oom(buf) ? -1 : 0; diff --git a/src/libgit2/object.h b/src/libgit2/object.h index b1fcd953a..980e8627e 100644 --- a/src/libgit2/object.h +++ b/src/libgit2/object.h @@ -49,7 +49,8 @@ int git_object__parse_oid_header( git_oid *oid, const char **buffer_out, const char *buffer_end, - const char *header); + const char *header, + git_oid_t oid_type); int git_object__write_oid_header( git_str *buf, diff --git a/src/libgit2/odb.c b/src/libgit2/odb.c index fed103ebb..3a7d08cbf 100644 --- a/src/libgit2/odb.c +++ b/src/libgit2/odb.c @@ -134,6 +134,7 @@ 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); } @@ -236,6 +237,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; done: git_hash_ctx_cleanup(&ctx); @@ -914,7 +916,7 @@ static int odb_exists_prefix_1(git_oid *out, git_odb *db, { size_t i; int error = GIT_ENOTFOUND, num_found = 0; - git_oid last_found = GIT_OID_SHA1_ZERO, found; + git_oid last_found = GIT_OID_NONE, found; if ((error = git_mutex_lock(&db->lock)) < 0) { git_error_set(GIT_ERROR_ODB, "failed to acquire the odb lock"); @@ -965,7 +967,7 @@ int git_odb_exists_prefix( git_oid *out, git_odb *db, const git_oid *short_id, size_t len) { int error; - git_oid key = GIT_OID_SHA1_ZERO; + git_oid key = GIT_OID_NONE; GIT_ASSERT_ARG(db); GIT_ASSERT_ARG(short_id); @@ -1049,7 +1051,7 @@ int git_odb_expand_ids( /* the object is missing or ambiguous */ case GIT_ENOTFOUND: case GIT_EAMBIGUOUS: - memset(&query->id, 0, sizeof(git_oid)); + git_oid_clear(&query->id, GIT_OID_SHA1); query->length = 0; query->type = 0; break; @@ -1305,7 +1307,7 @@ static int read_prefix_1(git_odb_object **out, git_odb *db, { size_t i; int error = 0; - git_oid found_full_oid = GIT_OID_SHA1_ZERO; + git_oid found_full_oid = GIT_OID_NONE; git_rawobj raw = {0}; void *data = NULL; bool found = false; @@ -1391,7 +1393,8 @@ out: int git_odb_read_prefix( git_odb_object **out, git_odb *db, const git_oid *short_id, size_t len) { - git_oid key = GIT_OID_SHA1_ZERO; + git_oid key = GIT_OID_NONE; + size_t hex_size; int error; GIT_ASSERT_ARG(out); @@ -1611,6 +1614,7 @@ int git_odb_stream_finalize_write(git_oid *out, git_odb_stream *stream) "stream_finalize_write()"); git_hash_final(out->id, stream->hash_ctx); + out->type = GIT_OID_SHA1; if (git_odb__freshen(stream->backend->odb, out)) return 0; diff --git a/src/libgit2/odb_loose.c b/src/libgit2/odb_loose.c index 4700f9749..f5013df5d 100644 --- a/src/libgit2/odb_loose.c +++ b/src/libgit2/odb_loose.c @@ -545,7 +545,7 @@ 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); + error = git_oid_fromstr(res_oid, (char *)state.res_oid, GIT_OID_SHA1); if (error) return error; @@ -733,6 +733,8 @@ 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; + return 0; } diff --git a/src/libgit2/oid.c b/src/libgit2/oid.c index 83f0fa59d..d3284bd6e 100644 --- a/src/libgit2/oid.c +++ b/src/libgit2/oid.c @@ -14,11 +14,13 @@ #include <limits.h> const git_oid git_oid__empty_blob_sha1 = - {{ 0xe6, 0x9d, 0xe2, 0x9b, 0xb2, 0xd1, 0xd6, 0x43, 0x4b, 0x8b, - 0x29, 0xae, 0x77, 0x5a, 0xd8, 0xc2, 0xe4, 0x8c, 0x53, 0x91 }}; + { GIT_OID_SHA1, + { 0xe6, 0x9d, 0xe2, 0x9b, 0xb2, 0xd1, 0xd6, 0x43, 0x4b, 0x8b, + 0x29, 0xae, 0x77, 0x5a, 0xd8, 0xc2, 0xe4, 0x8c, 0x53, 0x91 }}; const git_oid git_oid__empty_tree_sha1 = - {{ 0x4b, 0x82, 0x5d, 0xc6, 0x42, 0xcb, 0x6e, 0xb9, 0xa0, 0x60, - 0xe5, 0x4b, 0xf8, 0xd6, 0x92, 0x88, 0xfb, 0xee, 0x49, 0x04 }}; + { GIT_OID_SHA1, + { 0x4b, 0x82, 0x5d, 0xc6, 0x42, 0xcb, 0x6e, 0xb9, 0xa0, 0x60, + 0xe5, 0x4b, 0xf8, 0xd6, 0x92, 0x88, 0xfb, 0xee, 0x49, 0x04 }}; static char to_hex[] = "0123456789abcdef"; @@ -28,21 +30,29 @@ static int oid_error_invalid(const char *msg) return -1; } -int git_oid_fromstrn(git_oid *out, const char *str, size_t length) +int git_oid_fromstrn( + git_oid *out, + const char *str, + size_t length, + git_oid_t type) { - size_t p; + size_t size, p; int v; GIT_ASSERT_ARG(out); GIT_ASSERT_ARG(str); + if (!(size = git_oid_size(type))) + return oid_error_invalid("unknown type"); + if (!length) return oid_error_invalid("too short"); - if (length > GIT_OID_SHA1_HEXSIZE) + if (length > git_oid_hexsize(type)) return oid_error_invalid("too long"); - memset(out->id, 0, GIT_OID_SHA1_SIZE); + out->type = type; + memset(out->id, 0, size); for (p = 0; p < length; p++) { v = git__fromhex(str[p]); @@ -55,14 +65,14 @@ int git_oid_fromstrn(git_oid *out, const char *str, size_t length) return 0; } -int git_oid_fromstrp(git_oid *out, const char *str) +int git_oid_fromstrp(git_oid *out, const char *str, git_oid_t type) { - return git_oid_fromstrn(out, str, strlen(str)); + return git_oid_fromstrn(out, str, strlen(str), type); } -int git_oid_fromstr(git_oid *out, const char *str) +int git_oid_fromstr(git_oid *out, const char *str, git_oid_t type) { - return git_oid_fromstrn(out, str, GIT_OID_SHA1_HEXSIZE); + return git_oid_fromstrn(out, str, git_oid_hexsize(type), type); } GIT_INLINE(char) *fmt_one(char *str, unsigned int val) @@ -74,15 +84,19 @@ GIT_INLINE(char) *fmt_one(char *str, unsigned int val) int git_oid_nfmt(char *str, size_t n, const git_oid *oid) { - size_t i, max_i; + size_t hex_size, i, max_i; if (!oid) { memset(str, 0, n); return 0; } - if (n > GIT_OID_SHA1_HEXSIZE) { - memset(&str[GIT_OID_SHA1_HEXSIZE], 0, n - GIT_OID_SHA1_HEXSIZE); - n = GIT_OID_SHA1_HEXSIZE; + + if (!(hex_size = git_oid_hexsize(oid->type))) + return oid_error_invalid("unknown type"); + + if (n > hex_size) { + memset(&str[hex_size], 0, n - hex_size); + n = hex_size; } max_i = n / 2; @@ -98,16 +112,19 @@ int git_oid_nfmt(char *str, size_t n, const git_oid *oid) int git_oid_fmt(char *str, const git_oid *oid) { - return git_oid_nfmt(str, GIT_OID_SHA1_HEXSIZE, oid); + return git_oid_nfmt(str, git_oid_hexsize(oid->type), oid); } int git_oid_pathfmt(char *str, const git_oid *oid) { - size_t i; + size_t size, i; + + if (!(size = git_oid_size(oid->type))) + return oid_error_invalid("unknown type"); str = fmt_one(str, oid->id[0]); *str++ = '/'; - for (i = 1; i < sizeof(oid->id); i++) + for (i = 1; i < size; i++) str = fmt_one(str, oid->id[i]); return 0; @@ -116,26 +133,37 @@ int git_oid_pathfmt(char *str, const git_oid *oid) char *git_oid_tostr_s(const git_oid *oid) { char *str = GIT_THREADSTATE->oid_fmt; - git_oid_nfmt(str, GIT_OID_SHA1_HEXSIZE + 1, oid); + git_oid_nfmt(str, git_oid_hexsize(oid->type) + 1, oid); return str; } char *git_oid_allocfmt(const git_oid *oid) { - char *str = git__malloc(GIT_OID_SHA1_HEXSIZE + 1); - if (!str) + size_t hex_size = git_oid_hexsize(oid->type); + char *str = git__malloc(hex_size + 1); + + if (!hex_size || !str) return NULL; - git_oid_nfmt(str, GIT_OID_SHA1_HEXSIZE + 1, oid); + + if (git_oid_nfmt(str, hex_size + 1, oid) < 0) { + git__free(str); + return NULL; + } + return str; } char *git_oid_tostr(char *out, size_t n, const git_oid *oid) { + size_t hex_size; + if (!out || n == 0) return ""; - if (n > GIT_OID_SHA1_HEXSIZE + 1) - n = GIT_OID_SHA1_HEXSIZE + 1; + hex_size = oid ? git_oid_hexsize(oid->type) : 0; + + if (n > hex_size + 1) + n = hex_size + 1; git_oid_nfmt(out, n - 1, oid); /* allow room for terminating NUL */ out[n - 1] = '\0'; @@ -143,15 +171,27 @@ char *git_oid_tostr(char *out, size_t n, const git_oid *oid) return out; } -int git_oid_fromraw(git_oid *out, const unsigned char *raw) +int git_oid_fromraw(git_oid *out, const unsigned char *raw, git_oid_t type) { - memcpy(out->id, raw, sizeof(out->id)); + size_t size; + + if (!(size = git_oid_size(type))) + return oid_error_invalid("unknown type"); + + out->type = type; + memcpy(out->id, raw, size); return 0; } int git_oid_cpy(git_oid *out, const git_oid *src) { - return git_oid_raw_cpy(out->id, src->id); + size_t size; + + if (!(size = git_oid_size(src->type))) + return oid_error_invalid("unknown type"); + + out->type = src->type; + return git_oid_raw_cpy(out->id, src->id, size); } int git_oid_cmp(const git_oid *a, const git_oid *b) @@ -166,6 +206,9 @@ int git_oid_equal(const git_oid *a, const git_oid *b) int git_oid_ncmp(const git_oid *oid_a, const git_oid *oid_b, size_t len) { + if (oid_a->type != oid_b->type) + return oid_a->type - oid_b->type; + return git_oid_raw_ncmp(oid_a->id, oid_b->id, len); } @@ -173,9 +216,10 @@ int git_oid_strcmp(const git_oid *oid_a, const char *str) { const unsigned char *a; unsigned char strval; + long size = (long)git_oid_size(oid_a->type); int hexval; - for (a = oid_a->id; *str && (a - oid_a->id) < GIT_OID_SHA1_SIZE; ++a) { + for (a = oid_a->id; *str && (a - oid_a->id) < size; ++a) { if ((hexval = git__fromhex(*str++)) < 0) return -1; strval = (unsigned char)(hexval << 4); @@ -199,8 +243,14 @@ int git_oid_streq(const git_oid *oid_a, const char *str) int git_oid_is_zero(const git_oid *oid_a) { const unsigned char *a = oid_a->id; - unsigned int i; - for (i = 0; i < GIT_OID_SHA1_SIZE; ++i, ++a) + size_t size = git_oid_size(oid_a->type), i; + + if (!oid_a->type) + return 1; + else if (!size) + return 0; + + for (i = 0; i < size; ++i, ++a) if (*a != 0) return 0; return 1; diff --git a/src/libgit2/oid.h b/src/libgit2/oid.h index 9548ba2ab..f3df9aa39 100644 --- a/src/libgit2/oid.h +++ b/src/libgit2/oid.h @@ -11,6 +11,8 @@ #include "git2/oid.h" +#define GIT_OID_NONE { 0, { 0 } } + extern const git_oid git_oid__empty_blob_sha1; extern const git_oid git_oid__empty_tree_sha1; @@ -50,8 +52,8 @@ GIT_INLINE(int) git_oid_raw_ncmp( const unsigned char *sha2, size_t len) { - if (len > GIT_OID_SHA1_HEXSIZE) - len = GIT_OID_SHA1_HEXSIZE; + if (len > GIT_OID_MAX_HEXSIZE) + len = GIT_OID_MAX_HEXSIZE; while (len > 1) { if (*sha1 != *sha2) @@ -70,16 +72,18 @@ GIT_INLINE(int) git_oid_raw_ncmp( GIT_INLINE(int) git_oid_raw_cmp( const unsigned char *sha1, - const unsigned char *sha2) + const unsigned char *sha2, + size_t size) { - return memcmp(sha1, sha2, GIT_OID_SHA1_SIZE); + return memcmp(sha1, sha2, size); } GIT_INLINE(int) git_oid_raw_cpy( unsigned char *dst, - const unsigned char *src) + const unsigned char *src, + size_t size) { - memcpy(dst, src, GIT_OID_SHA1_SIZE); + memcpy(dst, src, size); return 0; } @@ -92,7 +96,10 @@ GIT_INLINE(int) git_oid_raw_cpy( */ GIT_INLINE(int) git_oid__cmp(const git_oid *a, const git_oid *b) { - return git_oid_raw_cmp(a->id, b->id); + if (a->type != b->type) + return a->type - b->type; + + return git_oid_raw_cmp(a->id, b->id, git_oid_size(a->type)); } GIT_INLINE(void) git_oid__cpy_prefix( @@ -104,7 +111,7 @@ GIT_INLINE(void) git_oid__cpy_prefix( out->id[len / 2] &= 0xF0; } -GIT_INLINE(bool) git_oid__is_hexstr(const char *str) +GIT_INLINE(bool) git_oid__is_hexstr(const char *str, git_oid_t type) { size_t i; @@ -113,7 +120,13 @@ GIT_INLINE(bool) git_oid__is_hexstr(const char *str) return false; } - return (i == GIT_OID_SHA1_HEXSIZE); + return (i == git_oid_hexsize(type)); +} + +GIT_INLINE(void) git_oid_clear(git_oid *out, git_oid_t type) +{ + memset(out->id, 0, git_oid_size(type)); + out->type = type; } #endif diff --git a/src/libgit2/pack.c b/src/libgit2/pack.c index 95593743e..18f51d107 100644 --- a/src/libgit2/pack.c +++ b/src/libgit2/pack.c @@ -1002,7 +1002,7 @@ int get_delta_base( *curpos += used; } else if (type == GIT_OBJECT_REF_DELTA) { git_oid base_oid; - git_oid_fromraw(&base_oid, base_info); + git_oid_fromraw(&base_oid, base_info, GIT_OID_SHA1); /* If we have the cooperative cache, search in it first */ if (p->has_cache) { @@ -1136,7 +1136,7 @@ static int packfile_open_locked(struct git_pack_file *p) idx_sha1 = ((unsigned char *)p->index_map.data) + p->index_map.len - 40; - if (git_oid_raw_cmp(sha1, idx_sha1) != 0) + if (git_oid_raw_cmp(sha1, idx_sha1, GIT_OID_SHA1_SIZE) != 0) goto cleanup; if (git_mwindow_file_register(&p->mwf) < 0) @@ -1362,7 +1362,7 @@ int git_pack_foreach_entry( git_array_clear(oids); GIT_ERROR_CHECK_ALLOC(oid); } - git_oid_fromraw(oid, p->oids[i]); + git_oid_fromraw(oid, p->oids[i], GIT_OID_SHA1); } git_mutex_unlock(&p->lock); @@ -1428,7 +1428,7 @@ int git_pack_foreach_entry_offset( ntohl(*((uint32_t *)(large_offset_ptr + 4))); } - git_oid_fromraw(¤t_oid, (index + 20 * i)); + git_oid_fromraw(¤t_oid, (index + 20 * i), GIT_OID_SHA1); if ((error = cb(¤t_oid, current_offset, data)) != 0) { error = git_error_set_after_callback(error); goto cleanup; @@ -1437,7 +1437,7 @@ int git_pack_foreach_entry_offset( } else { for (i = 0; i < p->num_objects; i++) { current_offset = ntohl(*(const uint32_t *)(index + 24 * i)); - git_oid_fromraw(¤t_oid, (index + 24 * i + 4)); + git_oid_fromraw(¤t_oid, (index + 24 * i + 4), GIT_OID_SHA1); if ((error = cb(¤t_oid, current_offset, data)) != 0) { error = git_error_set_after_callback(error); goto cleanup; @@ -1457,7 +1457,7 @@ int git_pack__lookup_sha1(const void *oid_lookup_table, size_t stride, unsigned while (lo < hi) { unsigned mi = (lo + hi) / 2; - int cmp = git_oid_raw_cmp(base + mi * stride, oid_prefix); + int cmp = git_oid_raw_cmp(base + mi * stride, oid_prefix, GIT_OID_SHA1_SIZE); if (!cmp) return mi; @@ -1566,7 +1566,7 @@ static int pack_entry_find_offset( } *offset_out = offset; - git_oid_fromraw(found_oid, current); + git_oid_fromraw(found_oid, current, GIT_OID_SHA1); #ifdef INDEX_DEBUG_LOOKUP { diff --git a/src/libgit2/parse.c b/src/libgit2/parse.c index 7527b5559..703a6cdff 100644 --- a/src/libgit2/parse.c +++ b/src/libgit2/parse.c @@ -105,7 +105,7 @@ int git_parse_advance_oid(git_oid *out, git_parse_ctx *ctx) { if (ctx->line_len < GIT_OID_SHA1_HEXSIZE) return -1; - if ((git_oid_fromstrn(out, ctx->line, GIT_OID_SHA1_HEXSIZE)) < 0) + if ((git_oid_fromstrn(out, ctx->line, GIT_OID_SHA1_HEXSIZE, GIT_OID_SHA1)) < 0) return -1; git_parse_advance_chars(ctx, GIT_OID_SHA1_HEXSIZE); return 0; diff --git a/src/libgit2/patch_parse.c b/src/libgit2/patch_parse.c index 0ca1e433d..a3c7a6458 100644 --- a/src/libgit2/patch_parse.c +++ b/src/libgit2/patch_parse.c @@ -174,7 +174,7 @@ static int parse_header_oid( } if (len < GIT_OID_MINPREFIXLEN || len > GIT_OID_SHA1_HEXSIZE || - git_oid_fromstrn(oid, ctx->parse_ctx.line, len) < 0) + git_oid_fromstrn(oid, ctx->parse_ctx.line, len, GIT_OID_SHA1) < 0) return git_parse_err("invalid hex formatted object id at line %"PRIuZ, ctx->parse_ctx.line_num); @@ -1065,12 +1065,12 @@ static int check_patch(git_patch_parsed *patch) return git_parse_err("patch with no hunks"); if (delta->status == GIT_DELTA_ADDED) { - memset(&delta->old_file.id, 0x0, sizeof(git_oid)); + git_oid_clear(&delta->old_file.id, GIT_OID_SHA1); delta->old_file.id_abbrev = 0; } if (delta->status == GIT_DELTA_DELETED) { - memset(&delta->new_file.id, 0x0, sizeof(git_oid)); + git_oid_clear(&delta->new_file.id, GIT_OID_SHA1); delta->new_file.id_abbrev = 0; } diff --git a/src/libgit2/push.c b/src/libgit2/push.c index da8aebadd..d477b4f0d 100644 --- a/src/libgit2/push.c +++ b/src/libgit2/push.c @@ -118,6 +118,9 @@ static int parse_refspec(git_push *push, push_spec **spec, const char *str) s = git__calloc(1, sizeof(*s)); GIT_ERROR_CHECK_ALLOC(s); + git_oid_clear(&s->loid, GIT_OID_SHA1); + git_oid_clear(&s->roid, GIT_OID_SHA1); + if (git_refspec__parse(&s->refspec, str, false) < 0) { git_error_set(GIT_ERROR_INVALID, "invalid refspec %s", str); goto on_error; diff --git a/src/libgit2/rebase.c b/src/libgit2/rebase.c index f0d528d69..4529168ad 100644 --- a/src/libgit2/rebase.c +++ b/src/libgit2/rebase.c @@ -171,7 +171,8 @@ GIT_INLINE(int) rebase_readoid( if ((error = rebase_readfile(str_out, state_path, filename)) < 0) return error; - if (str_out->size != GIT_OID_SHA1_HEXSIZE || git_oid_fromstr(out, str_out->ptr) < 0) { + if (str_out->size != GIT_OID_SHA1_HEXSIZE || + git_oid_fromstr(out, str_out->ptr, GIT_OID_SHA1) < 0) { git_error_set(GIT_ERROR_REBASE, "the file '%s' contains an invalid object ID", filename); return -1; } @@ -353,7 +354,7 @@ int git_rebase_open( git_str_rtrim(&orig_head_id); - if ((error = git_oid_fromstr(&rebase->orig_head_id, orig_head_id.ptr)) < 0) + if ((error = git_oid_fromstr(&rebase->orig_head_id, orig_head_id.ptr, GIT_OID_SHA1)) < 0) goto done; git_str_truncate(&path, state_path_len); @@ -364,7 +365,7 @@ int git_rebase_open( git_str_rtrim(&onto_id); - if ((error = git_oid_fromstr(&rebase->onto_id, onto_id.ptr)) < 0) + if ((error = git_oid_fromstr(&rebase->onto_id, onto_id.ptr, GIT_OID_SHA1)) < 0) goto done; if (!rebase->head_detached) @@ -1333,8 +1334,8 @@ static int rebase_copy_notes( if (strlen(fromstr) != GIT_OID_SHA1_HEXSIZE || strlen(tostr) != GIT_OID_SHA1_HEXSIZE || - git_oid_fromstr(&from, fromstr) < 0 || - git_oid_fromstr(&to, tostr) < 0) + git_oid_fromstr(&from, fromstr, GIT_OID_SHA1) < 0 || + git_oid_fromstr(&to, tostr, GIT_OID_SHA1) < 0) goto on_error; if ((error = rebase_copy_note(rebase, notes_ref.ptr, &from, &to, committer)) < 0) diff --git a/src/libgit2/refdb_fs.c b/src/libgit2/refdb_fs.c index 0d0656a63..87fcb9118 100644 --- a/src/libgit2/refdb_fs.c +++ b/src/libgit2/refdb_fs.c @@ -158,7 +158,7 @@ static int packed_reload(refdb_fs_backend *backend) /* parse "<OID> <refname>\n" */ - if (git_oid_fromstr(&oid, scan) < 0) + if (git_oid_fromstr(&oid, scan, GIT_OID_SHA1) < 0) goto parse_failed; scan += GIT_OID_SHA1_HEXSIZE; @@ -179,7 +179,7 @@ static int packed_reload(refdb_fs_backend *backend) /* look for optional "^<OID>\n" */ if (*scan == '^') { - if (git_oid_fromstr(&oid, scan + 1) < 0) + if (git_oid_fromstr(&oid, scan + 1, GIT_OID_SHA1) < 0) goto parse_failed; scan += GIT_OID_SHA1_HEXSIZE + 1; @@ -222,7 +222,7 @@ static int loose_parse_oid( goto corrupted; /* we need to get 40 OID characters from the file */ - if (git_oid_fromstr(oid, str) < 0) + if (git_oid_fromstr(oid, str, GIT_OID_SHA1) < 0) goto corrupted; /* If the file is longer than 40 chars, the 41st must be a space */ @@ -709,7 +709,7 @@ static int packed_lookup( git_oid oid, peel, *peel_ptr = NULL; if (data_end - rec < GIT_OID_SHA1_HEXSIZE || - git_oid_fromstr(&oid, rec) < 0) { + git_oid_fromstr(&oid, rec, GIT_OID_SHA1) < 0) { goto parse_failed; } rec += GIT_OID_SHA1_HEXSIZE + 1; @@ -725,7 +725,7 @@ static int packed_lookup( if (*rec == '^') { rec++; if (data_end - rec < GIT_OID_SHA1_HEXSIZE || - git_oid_fromstr(&peel, rec) < 0) { + git_oid_fromstr(&peel, rec, GIT_OID_SHA1) < 0) { goto parse_failed; } peel_ptr = &peel; diff --git a/src/libgit2/reflog.c b/src/libgit2/reflog.c index ca6d53808..1b03e83e7 100644 --- a/src/libgit2/reflog.c +++ b/src/libgit2/reflog.c @@ -104,7 +104,7 @@ int git_reflog_append(git_reflog *reflog, const git_oid *new_oid, const git_sign previous = git_reflog_entry_byindex(reflog, 0); if (previous == NULL) - git_oid_fromstr(&entry->oid_old, GIT_OID_SHA1_HEXZERO); + git_oid_fromstr(&entry->oid_old, GIT_OID_SHA1_HEXZERO, GIT_OID_SHA1); else git_oid_cpy(&entry->oid_old, &previous->oid_cur); @@ -218,8 +218,10 @@ int git_reflog_drop(git_reflog *reflog, size_t idx, int rewrite_previous_entry) /* If the oldest entry has just been removed... */ if (idx == entrycount - 1) { + git_oid zero = GIT_OID_SHA1_ZERO; + /* ...clear the oid_old member of the "new" oldest entry */ - if (git_oid_fromstr(&entry->oid_old, GIT_OID_SHA1_HEXZERO) < 0) + if (git_oid_cpy(&entry->oid_old, &zero) < 0) return -1; return 0; diff --git a/src/libgit2/refs.c b/src/libgit2/refs.c index 5c875b95b..8e4abaccc 100644 --- a/src/libgit2/refs.c +++ b/src/libgit2/refs.c @@ -86,6 +86,8 @@ git_reference *git_reference__alloc( if (peel != NULL) git_oid_cpy(&ref->peel, peel); + else + git_oid_clear(&ref->peel, GIT_OID_SHA1); return ref; } diff --git a/src/libgit2/remote.c b/src/libgit2/remote.c index 61805596f..3330347bd 100644 --- a/src/libgit2/remote.c +++ b/src/libgit2/remote.c @@ -1830,7 +1830,7 @@ static int update_one_tip( } if (error == GIT_ENOTFOUND) { - memset(&old, 0, sizeof(git_oid)); + git_oid_clear(&old, GIT_OID_SHA1); error = 0; if (autotag && (error = git_vector_insert(update_heads, head)) < 0) @@ -1892,10 +1892,10 @@ static int update_tips_for_spec( } /* Handle specified oid sources */ - if (git_oid__is_hexstr(spec->src)) { + if (git_oid__is_hexstr(spec->src, GIT_OID_SHA1)) { git_oid id; - if ((error = git_oid_fromstr(&id, spec->src)) < 0) + if ((error = git_oid_fromstr(&id, spec->src, GIT_OID_SHA1)) < 0) goto on_error; if (spec->dst && diff --git a/src/libgit2/revparse.c b/src/libgit2/revparse.c index 3226e28fa..1f3dc6c13 100644 --- a/src/libgit2/revparse.c +++ b/src/libgit2/revparse.c @@ -19,7 +19,7 @@ static int maybe_sha_or_abbrev(git_object **out, git_repository *repo, const cha { git_oid oid; - if (git_oid_fromstrn(&oid, spec, speclen) < 0) + if (git_oid_fromstrn(&oid, spec, speclen, GIT_OID_SHA1) < 0) return GIT_ENOTFOUND; return git_object_lookup_prefix(out, repo, &oid, speclen, GIT_OBJECT_ANY); diff --git a/src/libgit2/tag.c b/src/libgit2/tag.c index 28aa6ec51..e780279f8 100644 --- a/src/libgit2/tag.c +++ b/src/libgit2/tag.c @@ -76,7 +76,7 @@ static int tag_parse(git_tag *tag, const char *buffer, const char *buffer_end) int error; if (git_object__parse_oid_header(&tag->target, - &buffer, buffer_end, "object ") < 0) + &buffer, buffer_end, "object ", GIT_OID_SHA1) < 0) return tag_error("object field invalid"); if (buffer + 5 >= buffer_end) diff --git a/src/libgit2/transports/smart_pkt.c b/src/libgit2/transports/smart_pkt.c index 3b0c34484..b11417f3e 100644 --- a/src/libgit2/transports/smart_pkt.c +++ b/src/libgit2/transports/smart_pkt.c @@ -53,7 +53,8 @@ static int ack_pkt(git_pkt **out, const char *line, size_t len) line += 4; len -= 4; - if (len < GIT_OID_SHA1_HEXSIZE || git_oid_fromstr(&pkt->oid, line) < 0) + if (len < GIT_OID_SHA1_HEXSIZE || + git_oid_fromstr(&pkt->oid, line, GIT_OID_SHA1) < 0) goto out_err; line += GIT_OID_SHA1_HEXSIZE; len -= GIT_OID_SHA1_HEXSIZE; @@ -222,7 +223,8 @@ static int ref_pkt(git_pkt **out, const char *line, size_t len) GIT_ERROR_CHECK_ALLOC(pkt); pkt->type = GIT_PKT_REF; - if (len < GIT_OID_SHA1_HEXSIZE || git_oid_fromstr(&pkt->head.oid, line) < 0) + if (len < GIT_OID_SHA1_HEXSIZE || + git_oid_fromstr(&pkt->head.oid, line, GIT_OID_SHA1) < 0) goto out_err; line += GIT_OID_SHA1_HEXSIZE; len -= GIT_OID_SHA1_HEXSIZE; diff --git a/src/libgit2/tree-cache.c b/src/libgit2/tree-cache.c index 966e7df31..59d124c0c 100644 --- a/src/libgit2/tree-cache.c +++ b/src/libgit2/tree-cache.c @@ -114,7 +114,7 @@ static int read_tree_internal(git_tree_cache **out, if (buffer + GIT_OID_SHA1_SIZE > buffer_end) goto corrupted; - git_oid_fromraw(&tree->oid, (const unsigned char *)buffer); + git_oid_fromraw(&tree->oid, (const unsigned char *)buffer, GIT_OID_SHA1); buffer += GIT_OID_SHA1_SIZE; } diff --git a/src/libgit2/tree.c b/src/libgit2/tree.c index 9d3c67db0..0676192d3 100644 --- a/src/libgit2/tree.c +++ b/src/libgit2/tree.c @@ -425,7 +425,7 @@ int git_tree__parse_raw(void *_tree, const char *data, size_t size) entry->attr = attr; entry->filename_len = (uint16_t)filename_len; entry->filename = buffer; - git_oid_fromraw(&entry->oid, ((unsigned char *) buffer + filename_len + 1)); + git_oid_fromraw(&entry->oid, ((unsigned char *) buffer + filename_len + 1), GIT_OID_SHA1); } buffer += filename_len + 1; |