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

Function find_trailer_block_start

trailer.c:886–979  ·  view source on GitHub ↗

* Return the position of the first trailer line or len if there are no * trailers. */

Source from the content-addressed store, hash-verified

884 * trailers.
885 */
886static size_t find_trailer_block_start(const char *buf, size_t len)
887{
888 const char *s;
889 ssize_t end_of_title, l;
890 int only_spaces = 1;
891 int recognized_prefix = 0, trailer_lines = 0, non_trailer_lines = 0;
892 /*
893 * Number of possible continuation lines encountered. This will be
894 * reset to 0 if we encounter a trailer (since those lines are to be
895 * considered continuations of that trailer), and added to
896 * non_trailer_lines if we encounter a non-trailer (since those lines
897 * are to be considered non-trailers).
898 */
899 int possible_continuation_lines = 0;
900
901 /* The first paragraph is the title and cannot be trailers */
902 for (s = buf; s < buf + len; s = next_line(s)) {
903 if (starts_with_mem(s, buf + len - s, comment_line_str))
904 continue;
905 if (is_blank_line(s))
906 break;
907 }
908 end_of_title = s - buf;
909
910 /*
911 * Get the start of the trailers by looking starting from the end for a
912 * blank line before a set of non-blank lines that (i) are all
913 * trailers, or (ii) contains at least one Git-generated trailer and
914 * consists of at least 25% trailers.
915 */
916 for (l = last_line(buf, len);
917 l >= end_of_title;
918 l = last_line(buf, l)) {
919 const char *bol = buf + l;
920 const char **p;
921 ssize_t separator_pos;
922
923 if (starts_with_mem(bol, buf + len - bol, comment_line_str)) {
924 non_trailer_lines += possible_continuation_lines;
925 possible_continuation_lines = 0;
926 continue;
927 }
928 if (is_blank_line(bol)) {
929 if (only_spaces)
930 continue;
931 non_trailer_lines += possible_continuation_lines;
932 if (recognized_prefix &&
933 trailer_lines * 3 >= non_trailer_lines)
934 return next_line(bol) - buf;
935 else if (trailer_lines && !non_trailer_lines)
936 return next_line(bol) - buf;
937 return len;
938 }
939 only_spaces = 0;
940
941 for (p = git_generated_prefixes; *p; p++) {
942 if (starts_with(bol, *p)) {
943 trailer_lines++;

Callers 1

trailer_block_getFunction · 0.85

Calls 7

starts_with_memFunction · 0.85
last_lineFunction · 0.85
starts_withFunction · 0.85
find_separatorFunction · 0.85
token_matches_itemFunction · 0.85
next_lineFunction · 0.70
is_blank_lineFunction · 0.70

Tested by

no test coverage detected