Skip to content

Commit 9c5681d

Browse files
jonathantanmygitster
authored andcommitted
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>
1 parent 334192b commit 9c5681d

1 file changed

Lines changed: 18 additions & 17 deletions

File tree

mailinfo.c

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -557,37 +557,35 @@ static inline int patchbreak(const struct strbuf *line)
557557
return 0;
558558
}
559559

560-
static int is_scissors_line(const struct strbuf *line)
560+
static int is_scissors_line(const char *line)
561561
{
562-
size_t i, len = line->len;
562+
const char *c;
563563
int scissors = 0, gap = 0;
564-
int first_nonblank = -1;
565-
int last_nonblank = 0, visible, perforation = 0, in_perforation = 0;
566-
const char *buf = line->buf;
564+
const char *first_nonblank = NULL, *last_nonblank = NULL;
565+
int visible, perforation = 0, in_perforation = 0;
567566

568-
for (i = 0; i < len; i++) {
569-
if (isspace(buf[i])) {
567+
for (c = line; *c; c++) {
568+
if (isspace(*c)) {
570569
if (in_perforation) {
571570
perforation++;
572571
gap++;
573572
}
574573
continue;
575574
}
576-
last_nonblank = i;
577-
if (first_nonblank < 0)
578-
first_nonblank = i;
579-
if (buf[i] == '-') {
575+
last_nonblank = c;
576+
if (first_nonblank == NULL)
577+
first_nonblank = c;
578+
if (*c == '-') {
580579
in_perforation = 1;
581580
perforation++;
582581
continue;
583582
}
584-
if (i + 1 < len &&
585-
(!memcmp(buf + i, ">8", 2) || !memcmp(buf + i, "8<", 2) ||
586-
!memcmp(buf + i, ">%", 2) || !memcmp(buf + i, "%<", 2))) {
583+
if ((!memcmp(c, ">8", 2) || !memcmp(c, "8<", 2) ||
584+
!memcmp(c, ">%", 2) || !memcmp(c, "%<", 2))) {
587585
in_perforation = 1;
588586
perforation += 2;
589587
scissors += 2;
590-
i++;
588+
c++;
591589
continue;
592590
}
593591
in_perforation = 0;
@@ -602,7 +600,10 @@ static int is_scissors_line(const struct strbuf *line)
602600
* than half of the perforation.
603601
*/
604602

605-
visible = last_nonblank - first_nonblank + 1;
603+
if (first_nonblank && last_nonblank)
604+
visible = last_nonblank - first_nonblank + 1;
605+
else
606+
visible = 0;
606607
return (scissors && 8 <= visible &&
607608
visible < perforation * 3 &&
608609
gap * 2 < perforation);
@@ -647,7 +648,7 @@ static int handle_commit_msg(struct mailinfo *mi, struct strbuf *line)
647648
if (convert_to_utf8(mi, line, mi->charset.buf))
648649
return 0; /* mi->input_error already set */
649650

650-
if (mi->use_scissors && is_scissors_line(line)) {
651+
if (mi->use_scissors && is_scissors_line(line->buf)) {
651652
int i;
652653

653654
strbuf_setlen(&mi->log_message, 0);

0 commit comments

Comments
 (0)