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

Function crlf_to_worktree

convert.c:592–627  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

590}
591
592static int crlf_to_worktree(const char *src, size_t len, struct strbuf *buf,
593 enum convert_crlf_action crlf_action)
594{
595 char *to_free = NULL;
596 struct text_stat stats;
597
598 if (!len || output_eol(crlf_action) != EOL_CRLF)
599 return 0;
600
601 gather_stats(src, len, &stats);
602 if (!will_convert_lf_to_crlf(&stats, crlf_action))
603 return 0;
604
605 /* are we "faking" in place editing ? */
606 if (src == buf->buf)
607 to_free = strbuf_detach(buf, NULL);
608
609 strbuf_grow(buf, len + stats.lonelf);
610 for (;;) {
611 const char *nl = memchr(src, '\n', len);
612 if (!nl)
613 break;
614 if (nl > src && nl[-1] == '\r') {
615 strbuf_add(buf, src, nl + 1 - src);
616 } else {
617 strbuf_add(buf, src, nl - src);
618 strbuf_addstr(buf, "\r\n");
619 }
620 len -= nl + 1 - src;
621 src = nl + 1;
622 }
623 strbuf_add(buf, src, len);
624
625 free(to_free);
626 return 1;
627}
628
629struct filter_params {
630 const char *src;

Callers 1

Calls 7

output_eolFunction · 0.85
gather_statsFunction · 0.85
will_convert_lf_to_crlfFunction · 0.85
strbuf_detachFunction · 0.85
strbuf_growFunction · 0.85
strbuf_addFunction · 0.85
strbuf_addstrFunction · 0.85

Tested by

no test coverage detected