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:
parent
334192b411
commit
9c5681da88
33
mailinfo.c
33
mailinfo.c
@ -557,37 +557,35 @@ static inline int patchbreak(const struct strbuf *line)
|
|||||||
return 0;
|
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 scissors = 0, gap = 0;
|
||||||
int first_nonblank = -1;
|
const char *first_nonblank = NULL, *last_nonblank = NULL;
|
||||||
int last_nonblank = 0, visible, perforation = 0, in_perforation = 0;
|
int visible, perforation = 0, in_perforation = 0;
|
||||||
const char *buf = line->buf;
|
|
||||||
|
|
||||||
for (i = 0; i < len; i++) {
|
for (c = line; *c; c++) {
|
||||||
if (isspace(buf[i])) {
|
if (isspace(*c)) {
|
||||||
if (in_perforation) {
|
if (in_perforation) {
|
||||||
perforation++;
|
perforation++;
|
||||||
gap++;
|
gap++;
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
last_nonblank = i;
|
last_nonblank = c;
|
||||||
if (first_nonblank < 0)
|
if (first_nonblank == NULL)
|
||||||
first_nonblank = i;
|
first_nonblank = c;
|
||||||
if (buf[i] == '-') {
|
if (*c == '-') {
|
||||||
in_perforation = 1;
|
in_perforation = 1;
|
||||||
perforation++;
|
perforation++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (i + 1 < len &&
|
if ((!memcmp(c, ">8", 2) || !memcmp(c, "8<", 2) ||
|
||||||
(!memcmp(buf + i, ">8", 2) || !memcmp(buf + i, "8<", 2) ||
|
!memcmp(c, ">%", 2) || !memcmp(c, "%<", 2))) {
|
||||||
!memcmp(buf + i, ">%", 2) || !memcmp(buf + i, "%<", 2))) {
|
|
||||||
in_perforation = 1;
|
in_perforation = 1;
|
||||||
perforation += 2;
|
perforation += 2;
|
||||||
scissors += 2;
|
scissors += 2;
|
||||||
i++;
|
c++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
in_perforation = 0;
|
in_perforation = 0;
|
||||||
@ -602,7 +600,10 @@ static int is_scissors_line(const struct strbuf *line)
|
|||||||
* than half of the perforation.
|
* than half of the perforation.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
if (first_nonblank && last_nonblank)
|
||||||
visible = last_nonblank - first_nonblank + 1;
|
visible = last_nonblank - first_nonblank + 1;
|
||||||
|
else
|
||||||
|
visible = 0;
|
||||||
return (scissors && 8 <= visible &&
|
return (scissors && 8 <= visible &&
|
||||||
visible < perforation * 3 &&
|
visible < perforation * 3 &&
|
||||||
gap * 2 < perforation);
|
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))
|
if (convert_to_utf8(mi, line, mi->charset.buf))
|
||||||
return 0; /* mi->input_error already set */
|
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;
|
int i;
|
||||||
|
|
||||||
strbuf_setlen(&mi->log_message, 0);
|
strbuf_setlen(&mi->log_message, 0);
|
||||||
|
Loading…
Reference in New Issue
Block a user