| 982 | } |
| 983 | |
| 984 | static int index_mem(struct index_state *istate, |
| 985 | struct object_id *oid, |
| 986 | const void *buf, size_t size, |
| 987 | enum object_type type, |
| 988 | const char *path, unsigned flags) |
| 989 | { |
| 990 | struct strbuf nbuf = STRBUF_INIT; |
| 991 | int ret = 0; |
| 992 | int write_object = flags & INDEX_WRITE_OBJECT; |
| 993 | |
| 994 | if (!type) |
| 995 | type = OBJ_BLOB; |
| 996 | |
| 997 | /* |
| 998 | * Convert blobs to git internal format |
| 999 | */ |
| 1000 | if ((type == OBJ_BLOB) && path) { |
| 1001 | if (convert_to_git(istate, path, buf, size, &nbuf, |
| 1002 | get_conv_flags(flags))) { |
| 1003 | buf = nbuf.buf; |
| 1004 | size = nbuf.len; |
| 1005 | } |
| 1006 | } |
| 1007 | if (flags & INDEX_FORMAT_CHECK) { |
| 1008 | struct fsck_options opts; |
| 1009 | |
| 1010 | fsck_options_init(&opts, the_repository, FSCK_OPTIONS_DEFAULT); |
| 1011 | opts.strict = 1; |
| 1012 | opts.error_func = hash_format_check_report; |
| 1013 | if (fsck_buffer(null_oid(istate->repo->hash_algo), type, buf, size, &opts)) |
| 1014 | die(_("refusing to create malformed object")); |
| 1015 | fsck_finish(&opts); |
| 1016 | } |
| 1017 | |
| 1018 | if (write_object) |
| 1019 | ret = odb_write_object(istate->repo->objects, buf, size, type, oid); |
| 1020 | else |
| 1021 | hash_object_file(istate->repo->hash_algo, buf, size, type, oid); |
| 1022 | |
| 1023 | strbuf_release(&nbuf); |
| 1024 | return ret; |
| 1025 | } |
| 1026 | |
| 1027 | static int index_stream_convert_blob(struct index_state *istate, |
| 1028 | struct object_id *oid, |
no test coverage detected