mailinfo: make is_scissors_line take plain char *

The is_scissors_line takes a struct strbuf * when a char * would
suffice. Make it take char *.

Signed-off-by: Jonathan Tan <jonathantanmy@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Jonathan Tan 2016-09-19 14:08:52 -07:00 committed by Junio C Hamano
parent 334192b411
commit 9c5681da88

View File

@ -557,37 +557,35 @@ static inline int patchbreak(const struct strbuf *line)
return 0;
}
static int is_scissors_line(const struct strbuf *line)
static int is_scissors_line(const char *line)
{
size_t i, len = line->len;
const char *c;
int scissors = 0, gap = 0;
int first_nonblank = -1;
int last_nonblank = 0, visible, perforation = 0, in_perforation = 0;
const char *buf = line->buf;
const char *first_nonblank = NULL, *last_nonblank = NULL;
int visible, perforation = 0, in_perforation = 0;
for (i = 0; i < len; i++) {
if (isspace(buf[i])) {
for (c = line; *c; c++) {
if (isspace(*c)) {
if (in_perforation) {
perforation++;
gap++;
}
continue;
}
last_nonblank = i;
if (first_nonblank < 0)
first_nonblank = i;
if (buf[i] == '-') {
last_nonblank = c;
if (first_nonblank == NULL)
first_nonblank = c;
if (*c == '-') {
in_perforation = 1;
perforation++;
continue;
}
if (i + 1 < len &&
(!memcmp(buf + i, ">8", 2) || !memcmp(buf + i, "8<", 2) ||
!memcmp(buf + i, ">%", 2) || !memcmp(buf + i, "%<", 2))) {
if ((!memcmp(c, ">8", 2) || !memcmp(c, "8<", 2) ||
!memcmp(c, ">%", 2) || !memcmp(c, "%<", 2))) {
in_perforation = 1;
perforation += 2;
scissors += 2;
i++;
c++;
continue;
}
in_perforation = 0;
@ -602,7 +600,10 @@ static int is_scissors_line(const struct strbuf *line)
* than half of the perforation.
*/
visible = last_nonblank - first_nonblank + 1;
if (first_nonblank && last_nonblank)
visible = last_nonblank - first_nonblank + 1;
else
visible = 0;
return (scissors && 8 <= visible &&
visible < perforation * 3 &&
gap * 2 < perforation);
@ -647,7 +648,7 @@ static int handle_commit_msg(struct mailinfo *mi, struct strbuf *line)
if (convert_to_utf8(mi, line, mi->charset.buf))
return 0; /* mi->input_error already set */
if (mi->use_scissors && is_scissors_line(line)) {
if (mi->use_scissors && is_scissors_line(line->buf)) {
int i;
strbuf_setlen(&mi->log_message, 0);