* While doing rename detection and pickaxe operation, we may need to * grab the data for the blob (or file) for our own in-core comparison. * diff_filespec has data and size fields for this purpose. */
| 4495 | * diff_filespec has data and size fields for this purpose. |
| 4496 | */ |
| 4497 | int diff_populate_filespec(struct repository *r, |
| 4498 | struct diff_filespec *s, |
| 4499 | const struct diff_populate_filespec_options *options) |
| 4500 | { |
| 4501 | int size_only = options ? options->check_size_only : 0; |
| 4502 | int check_binary = options ? options->check_binary : 0; |
| 4503 | int err = 0; |
| 4504 | int conv_flags = global_conv_flags_eol; |
| 4505 | /* |
| 4506 | * demote FAIL to WARN to allow inspecting the situation |
| 4507 | * instead of refusing. |
| 4508 | */ |
| 4509 | if (conv_flags & CONV_EOL_RNDTRP_DIE) |
| 4510 | conv_flags = CONV_EOL_RNDTRP_WARN; |
| 4511 | |
| 4512 | if (!DIFF_FILE_VALID(s)) |
| 4513 | die("internal error: asking to populate invalid file."); |
| 4514 | if (S_ISDIR(s->mode)) |
| 4515 | return -1; |
| 4516 | |
| 4517 | if (s->data) |
| 4518 | return 0; |
| 4519 | |
| 4520 | if (size_only && 0 < s->size) |
| 4521 | return 0; |
| 4522 | |
| 4523 | if (S_ISGITLINK(s->mode)) |
| 4524 | return diff_populate_gitlink(s, size_only); |
| 4525 | |
| 4526 | if (!s->oid_valid || |
| 4527 | reuse_worktree_file(r->index, s->path, &s->oid, 0)) { |
| 4528 | struct strbuf buf = STRBUF_INIT; |
| 4529 | struct stat st; |
| 4530 | int fd; |
| 4531 | |
| 4532 | if (lstat(s->path, &st) < 0) { |
| 4533 | err_empty: |
| 4534 | err = -1; |
| 4535 | empty: |
| 4536 | s->data = (char *)""; |
| 4537 | s->size = 0; |
| 4538 | return err; |
| 4539 | } |
| 4540 | s->size = xsize_t(st.st_size); |
| 4541 | if (!s->size) |
| 4542 | goto empty; |
| 4543 | if (S_ISLNK(st.st_mode)) { |
| 4544 | struct strbuf sb = STRBUF_INIT; |
| 4545 | |
| 4546 | if (strbuf_readlink(&sb, s->path, s->size)) |
| 4547 | goto err_empty; |
| 4548 | s->size = sb.len; |
| 4549 | s->data = strbuf_detach(&sb, NULL); |
| 4550 | s->should_free = 1; |
| 4551 | return 0; |
| 4552 | } |
| 4553 | |
| 4554 | /* |
no test coverage detected