| 1068 | #define SMALL_FILE_SIZE (32*1024) |
| 1069 | |
| 1070 | static int index_core(struct index_state *istate, |
| 1071 | struct object_id *oid, int fd, size_t size, |
| 1072 | enum object_type type, const char *path, |
| 1073 | unsigned flags) |
| 1074 | { |
| 1075 | int ret; |
| 1076 | |
| 1077 | if (!size) { |
| 1078 | ret = index_mem(istate, oid, "", size, type, path, flags); |
| 1079 | } else if (size <= SMALL_FILE_SIZE) { |
| 1080 | char *buf = xmalloc(size); |
| 1081 | ssize_t read_result = read_in_full(fd, buf, size); |
| 1082 | if (read_result < 0) |
| 1083 | ret = error_errno(_("read error while indexing %s"), |
| 1084 | path ? path : "<unknown>"); |
| 1085 | else if ((size_t) read_result != size) |
| 1086 | ret = error(_("short read while indexing %s"), |
| 1087 | path ? path : "<unknown>"); |
| 1088 | else |
| 1089 | ret = index_mem(istate, oid, buf, size, type, path, flags); |
| 1090 | free(buf); |
| 1091 | } else { |
| 1092 | void *buf = xmmap(NULL, size, PROT_READ, MAP_PRIVATE, fd, 0); |
| 1093 | ret = index_mem(istate, oid, buf, size, type, path, flags); |
| 1094 | munmap(buf, size); |
| 1095 | } |
| 1096 | return ret; |
| 1097 | } |
| 1098 | |
| 1099 | static int already_written(struct odb_transaction_files *transaction, |
| 1100 | struct object_id *oid) |
no test coverage detected