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

Function is_scissors_line

mailinfo.c:695–745  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

693}
694
695static int is_scissors_line(const char *line)
696{
697 const char *c;
698 int scissors = 0, gap = 0;
699 const char *first_nonblank = NULL, *last_nonblank = NULL;
700 int visible, perforation = 0, in_perforation = 0;
701
702 for (c = line; *c; c++) {
703 if (isspace(*c)) {
704 if (in_perforation) {
705 perforation++;
706 gap++;
707 }
708 continue;
709 }
710 last_nonblank = c;
711 if (!first_nonblank)
712 first_nonblank = c;
713 if (*c == '-') {
714 in_perforation = 1;
715 perforation++;
716 continue;
717 }
718 if (starts_with(c, ">8") || starts_with(c, "8<") ||
719 starts_with(c, ">%") || starts_with(c, "%<")) {
720 in_perforation = 1;
721 perforation += 2;
722 scissors += 2;
723 c++;
724 continue;
725 }
726 in_perforation = 0;
727 }
728
729 /*
730 * The mark must be at least 8 bytes long (e.g. "-- >8 --").
731 * Even though there can be arbitrary cruft on the same line
732 * (e.g. "cut here"), in order to avoid misidentification, the
733 * perforation must occupy more than a third of the visible
734 * width of the line, and dashes and scissors must occupy more
735 * than half of the perforation.
736 */
737
738 if (first_nonblank && last_nonblank)
739 visible = last_nonblank - first_nonblank + 1;
740 else
741 visible = 0;
742 return (scissors && 8 <= visible &&
743 visible < perforation * 3 &&
744 gap * 2 < perforation);
745}
746
747static void flush_inbody_header_accum(struct mailinfo *mi)
748{

Callers 2

check_inbody_headerFunction · 0.70
handle_commit_msgFunction · 0.70

Calls 1

starts_withFunction · 0.85

Tested by

no test coverage detected