Andrew's git
/
gitweb.git
/ diff
summary
|
log
|
commit
| diff |
tree
commit
grep
author
committer
pickaxe
?
re
mailinfo: make is_scissors_line take plain char *
author
Jonathan Tan
<jonathantanmy@google.com>
Mon, 19 Sep 2016 21:08:52 +0000
(14:08 -0700)
committer
Junio C Hamano
<gitster@pobox.com>
Mon, 19 Sep 2016 21:40:36 +0000
(14:40 -0700)
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>
mailinfo.c
patch
|
blob
|
history
raw
|
patch
|
inline
| side by side (parent:
334192b
)
diff --git
a/mailinfo.c
b/mailinfo.c
index 0c4738a70e2feaf9200a77f54ffa30818070e061..69391aaca13ed121ada52b3f2af8d96af3c8c84b 100644
(file)
--- a/
mailinfo.c
+++ b/
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;
- 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;
}
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;
}
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;
in_perforation = 1;
perforation += 2;
scissors += 2;
-
i
++;
+
c
++;
continue;
}
in_perforation = 0;
continue;
}
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.
*/
- 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);
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 (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);
int i;
strbuf_setlen(&mi->log_message, 0);