Move is_scissors_line to commit.c and expose it through commit.h. This is needed in commit.c, and mailinfo.c shouldn't really own it. --- commit.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ commit.h | 1 + mailinfo.c | 53 +---------------------------------------------------- 3 files changed, 54 insertions(+), 52 deletions(-) diff --git a/commit.c b/commit.c index fab826973..041cfa5a9 100644 --- a/commit.c +++ b/commit.c @@ -1646,6 +1646,58 @@ const char *find_commit_header(const char *msg, const char *key, size_t *out_len return NULL; } +int is_scissors_line(const char *line) +{ + const char *c; + int scissors = 0, gap = 0; + const char *first_nonblank = NULL, *last_nonblank = NULL; + int visible, perforation = 0, in_perforation = 0; + + for (c = line; *c != '\n'; c++) { + if (isspace(*c)) { + if (in_perforation) { + perforation++; + gap++; + } + continue; + } + last_nonblank = c; + if (first_nonblank == NULL) + first_nonblank = c; + if (*c == '-') { + in_perforation = 1; + perforation++; + continue; + } + if ((!memcmp(c, ">8", 2) || !memcmp(c, "8<", 2) || + !memcmp(c, ">%", 2) || !memcmp(c, "%<", 2))) { + in_perforation = 1; + perforation += 2; + scissors += 2; + c++; + continue; + } + in_perforation = 0; + } + + /* + * The mark must be at least 8 bytes long (e.g. "-- >8 --"). + * Even though there can be arbitrary cruft on the same line + * (e.g. "cut here"), in order to avoid misidentification, the + * perforation must occupy more than a third of the visible + * width of the line, and dashes and scissors must occupy more + * than half of the perforation. + */ + + if (first_nonblank && last_nonblank) + visible = last_nonblank - first_nonblank + 1; + else + visible = 0; + return (scissors && 8 <= visible && + visible < perforation * 3 && + gap * 2 < perforation); +} + /* * Inspect the given string and determine the true "end" of the log message, in * order to find where to put a new Signed-off-by: line. Ignored are diff --git a/commit.h b/commit.h index 9c12abb91..58cbab1cd 100644 --- a/commit.h +++ b/commit.h @@ -353,6 +353,7 @@ extern void free_commit_extra_headers(struct commit_extra_header *extra); */ extern const char *find_commit_header(const char *msg, const char *key, size_t *out_len); +extern int is_scissors_line(const char *line); /* Find the end of the log message, the right place for a new trailer. */ extern int ignore_non_trailer(const char *buf, size_t len); diff --git a/mailinfo.c b/mailinfo.c index eadd0597f..52af800a5 100644 --- a/mailinfo.c +++ b/mailinfo.c @@ -1,6 +1,7 @@ #include "cache.h" #include "utf8.h" #include "strbuf.h" +#include "commit.h" #include "mailinfo.h" static void cleanup_space(struct strbuf *sb) @@ -654,58 +655,6 @@ static inline int patchbreak(const struct strbuf *line) return 0; } -static int is_scissors_line(const char *line) -{ - const char *c; - int scissors = 0, gap = 0; - const char *first_nonblank = NULL, *last_nonblank = NULL; - int visible, perforation = 0, in_perforation = 0; - - for (c = line; *c != '\n'; c++) { - if (isspace(*c)) { - if (in_perforation) { - perforation++; - gap++; - } - continue; - } - last_nonblank = c; - if (first_nonblank == NULL) - first_nonblank = c; - if (*c == '-') { - in_perforation = 1; - perforation++; - continue; - } - if ((!memcmp(c, ">8", 2) || !memcmp(c, "8<", 2) || - !memcmp(c, ">%", 2) || !memcmp(c, "%<", 2))) { - in_perforation = 1; - perforation += 2; - scissors += 2; - c++; - continue; - } - in_perforation = 0; - } - - /* - * The mark must be at least 8 bytes long (e.g. "-- >8 --"). - * Even though there can be arbitrary cruft on the same line - * (e.g. "cut here"), in order to avoid misidentification, the - * perforation must occupy more than a third of the visible - * width of the line, and dashes and scissors must occupy more - * than half of the perforation. - */ - - if (first_nonblank && last_nonblank) - visible = last_nonblank - first_nonblank + 1; - else - visible = 0; - return (scissors && 8 <= visible && - visible < perforation * 3 && - gap * 2 < perforation); -} - static void flush_inbody_header_accum(struct mailinfo *mi) { if (!mi->inbody_header_accum.len) -- 2.12.3.3.g39c96af