| 1131 | } |
| 1132 | |
| 1133 | static int hash_blob_stream(struct odb_write_stream *stream, |
| 1134 | const struct git_hash_algo *hash_algo, |
| 1135 | struct object_id *result_oid, size_t size) |
| 1136 | { |
| 1137 | unsigned char buf[16384]; |
| 1138 | struct git_hash_ctx ctx; |
| 1139 | unsigned header_len; |
| 1140 | size_t bytes_hashed = 0; |
| 1141 | |
| 1142 | header_len = format_object_header((char *)buf, sizeof(buf), |
| 1143 | OBJ_BLOB, size); |
| 1144 | hash_algo->init_fn(&ctx); |
| 1145 | git_hash_update(&ctx, buf, header_len); |
| 1146 | |
| 1147 | while (!stream->is_finished) { |
| 1148 | ssize_t read_result = odb_write_stream_read(stream, buf, |
| 1149 | sizeof(buf)); |
| 1150 | |
| 1151 | if (read_result < 0) |
| 1152 | return -1; |
| 1153 | |
| 1154 | git_hash_update(&ctx, buf, read_result); |
| 1155 | bytes_hashed += read_result; |
| 1156 | } |
| 1157 | |
| 1158 | if (bytes_hashed != size) |
| 1159 | return -1; |
| 1160 | |
| 1161 | git_hash_final_oid(result_oid, &ctx); |
| 1162 | |
| 1163 | return 0; |
| 1164 | } |
| 1165 | |
| 1166 | /* |
| 1167 | * Read the contents from the stream provided, streaming it to the |
no test coverage detected