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

Function crlf_to_git

convert.c:503–590  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

501}
502
503static int crlf_to_git(struct index_state *istate,
504 const char *path, const char *src, size_t len,
505 struct strbuf *buf,
506 enum convert_crlf_action crlf_action, int conv_flags)
507{
508 struct text_stat stats;
509 char *dst;
510 int convert_crlf_into_lf;
511
512 if (crlf_action == CRLF_BINARY ||
513 (src && !len))
514 return 0;
515
516 /*
517 * If we are doing a dry-run and have no source buffer, there is
518 * nothing to analyze; we must assume we would convert.
519 */
520 if (!buf && !src)
521 return 1;
522
523 gather_stats(src, len, &stats);
524 /* Optimization: No CRLF? Nothing to convert, regardless. */
525 convert_crlf_into_lf = !!stats.crlf;
526
527 if (crlf_action == CRLF_AUTO || crlf_action == CRLF_AUTO_INPUT || crlf_action == CRLF_AUTO_CRLF) {
528 if (convert_is_binary(&stats))
529 return 0;
530 /*
531 * If the file in the index has any CR in it, do not
532 * convert. This is the new safer autocrlf handling,
533 * unless we want to renormalize in a merge or
534 * cherry-pick.
535 */
536 if ((!(conv_flags & CONV_EOL_RENORMALIZE)) &&
537 has_crlf_in_index(istate, path))
538 convert_crlf_into_lf = 0;
539 }
540 if (((conv_flags & CONV_EOL_RNDTRP_WARN) ||
541 ((conv_flags & CONV_EOL_RNDTRP_DIE) && len))) {
542 struct text_stat new_stats;
543 memcpy(&new_stats, &stats, sizeof(new_stats));
544 /* simulate "git add" */
545 if (convert_crlf_into_lf) {
546 new_stats.lonelf += new_stats.crlf;
547 new_stats.crlf = 0;
548 }
549 /* simulate "git checkout" */
550 if (will_convert_lf_to_crlf(&new_stats, crlf_action)) {
551 new_stats.crlf += new_stats.lonelf;
552 new_stats.lonelf = 0;
553 }
554 check_global_conv_flags_eol(path, &stats, &new_stats, conv_flags);
555 }
556 if (!convert_crlf_into_lf)
557 return 0;
558
559 /*
560 * At this point all of our source analysis is done, and we are sure we

Callers 2

convert_to_gitFunction · 0.85
convert_to_git_filter_fdFunction · 0.85

Calls 8

gather_statsFunction · 0.85
convert_is_binaryFunction · 0.85
has_crlf_in_indexFunction · 0.85
will_convert_lf_to_crlfFunction · 0.85
strbuf_availFunction · 0.85
strbuf_growFunction · 0.85
strbuf_setlenFunction · 0.85

Tested by

no test coverage detected