MCPcopy Create free account
hub / github.com/git/git / diff_populate_filespec

Function diff_populate_filespec

diff.c:4497–4642  ·  view source on GitHub ↗

* 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. */

Source from the content-addressed store, hash-verified

4495 * diff_filespec has data and size fields for this purpose.
4496 */
4497int 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 /*

Callers 14

fill_line_endsFunction · 0.85
process_diff_filepairFunction · 0.85
should_breakFunction · 0.85
estimate_similarityFunction · 0.85
hash_filespecFunction · 0.85
fill_mmfileFunction · 0.85
diff_filespec_sizeFunction · 0.85
show_dirstatFunction · 0.85
diff_filespec_is_binaryFunction · 0.85
builtin_diffstatFunction · 0.85
prepare_temp_fileFunction · 0.85

Calls 13

diff_populate_gitlinkFunction · 0.85
reuse_worktree_fileFunction · 0.85
xsize_tFunction · 0.85
strbuf_readlinkFunction · 0.85
strbuf_detachFunction · 0.85
would_convert_to_gitFunction · 0.85
xmmapFunction · 0.85
convert_to_gitFunction · 0.85
oid_to_hexFunction · 0.85
cast_size_t_to_ulongFunction · 0.85

Tested by

no test coverage detected