Merge branch 'rs/pp-user-info-without-extra-allocation'
* rs/pp-user-info-without-extra-allocation: pretty: remove intermediate strbufs from pp_user_info() pretty: simplify output line length calculation in pp_user_info() pretty: simplify input line length calculation in pp_user_info()
This commit is contained in:
commit
d9291ecf4f
49
pretty.c
49
pretty.c
@ -410,10 +410,7 @@ void pp_user_info(const struct pretty_print_context *pp,
|
|||||||
const char *what, struct strbuf *sb,
|
const char *what, struct strbuf *sb,
|
||||||
const char *line, const char *encoding)
|
const char *line, const char *encoding)
|
||||||
{
|
{
|
||||||
struct strbuf name;
|
|
||||||
struct strbuf mail;
|
|
||||||
struct ident_split ident;
|
struct ident_split ident;
|
||||||
int linelen;
|
|
||||||
char *line_end;
|
char *line_end;
|
||||||
const char *mailbuf, *namebuf;
|
const char *mailbuf, *namebuf;
|
||||||
size_t namelen, maillen;
|
size_t namelen, maillen;
|
||||||
@ -422,17 +419,9 @@ void pp_user_info(const struct pretty_print_context *pp,
|
|||||||
if (pp->fmt == CMIT_FMT_ONELINE)
|
if (pp->fmt == CMIT_FMT_ONELINE)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
line_end = strchr(line, '\n');
|
line_end = strchrnul(line, '\n');
|
||||||
if (!line_end) {
|
if (split_ident_line(&ident, line, line_end - line))
|
||||||
line_end = strchr(line, '\0');
|
|
||||||
if (!line_end)
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
linelen = ++line_end - line;
|
|
||||||
if (split_ident_line(&ident, line, linelen))
|
|
||||||
return;
|
|
||||||
|
|
||||||
|
|
||||||
mailbuf = ident.mail_begin;
|
mailbuf = ident.mail_begin;
|
||||||
maillen = ident.mail_end - ident.mail_begin;
|
maillen = ident.mail_end - ident.mail_begin;
|
||||||
@ -442,43 +431,33 @@ void pp_user_info(const struct pretty_print_context *pp,
|
|||||||
if (pp->mailmap)
|
if (pp->mailmap)
|
||||||
map_user(pp->mailmap, &mailbuf, &maillen, &namebuf, &namelen);
|
map_user(pp->mailmap, &mailbuf, &maillen, &namebuf, &namelen);
|
||||||
|
|
||||||
strbuf_init(&mail, 0);
|
|
||||||
strbuf_init(&name, 0);
|
|
||||||
|
|
||||||
strbuf_add(&mail, mailbuf, maillen);
|
|
||||||
strbuf_add(&name, namebuf, namelen);
|
|
||||||
|
|
||||||
namelen = name.len + mail.len + 3; /* ' ' + '<' + '>' */
|
|
||||||
|
|
||||||
if (pp->fmt == CMIT_FMT_EMAIL) {
|
if (pp->fmt == CMIT_FMT_EMAIL) {
|
||||||
strbuf_addstr(sb, "From: ");
|
strbuf_addstr(sb, "From: ");
|
||||||
if (needs_rfc2047_encoding(name.buf, name.len, RFC2047_ADDRESS)) {
|
if (needs_rfc2047_encoding(namebuf, namelen, RFC2047_ADDRESS)) {
|
||||||
add_rfc2047(sb, name.buf, name.len,
|
add_rfc2047(sb, namebuf, namelen,
|
||||||
encoding, RFC2047_ADDRESS);
|
encoding, RFC2047_ADDRESS);
|
||||||
max_length = 76; /* per rfc2047 */
|
max_length = 76; /* per rfc2047 */
|
||||||
} else if (needs_rfc822_quoting(name.buf, name.len)) {
|
} else if (needs_rfc822_quoting(namebuf, namelen)) {
|
||||||
struct strbuf quoted = STRBUF_INIT;
|
struct strbuf quoted = STRBUF_INIT;
|
||||||
add_rfc822_quoted("ed, name.buf, name.len);
|
add_rfc822_quoted("ed, namebuf, namelen);
|
||||||
strbuf_add_wrapped_bytes(sb, quoted.buf, quoted.len,
|
strbuf_add_wrapped_bytes(sb, quoted.buf, quoted.len,
|
||||||
-6, 1, max_length);
|
-6, 1, max_length);
|
||||||
strbuf_release("ed);
|
strbuf_release("ed);
|
||||||
} else {
|
} else {
|
||||||
strbuf_add_wrapped_bytes(sb, name.buf, name.len,
|
strbuf_add_wrapped_bytes(sb, namebuf, namelen,
|
||||||
-6, 1, max_length);
|
-6, 1, max_length);
|
||||||
}
|
}
|
||||||
if (namelen - name.len + last_line_length(sb) > max_length)
|
|
||||||
|
if (max_length <
|
||||||
|
last_line_length(sb) + strlen(" <") + maillen + strlen(">"))
|
||||||
strbuf_addch(sb, '\n');
|
strbuf_addch(sb, '\n');
|
||||||
|
strbuf_addf(sb, " <%.*s>\n", (int)maillen, mailbuf);
|
||||||
strbuf_addf(sb, " <%s>\n", mail.buf);
|
|
||||||
} else {
|
} else {
|
||||||
strbuf_addf(sb, "%s: %.*s%s <%s>\n", what,
|
strbuf_addf(sb, "%s: %.*s%.*s <%.*s>\n", what,
|
||||||
(pp->fmt == CMIT_FMT_FULLER) ? 4 : 0,
|
(pp->fmt == CMIT_FMT_FULLER) ? 4 : 0, " ",
|
||||||
" ", name.buf, mail.buf);
|
(int)namelen, namebuf, (int)maillen, mailbuf);
|
||||||
}
|
}
|
||||||
|
|
||||||
strbuf_release(&mail);
|
|
||||||
strbuf_release(&name);
|
|
||||||
|
|
||||||
switch (pp->fmt) {
|
switch (pp->fmt) {
|
||||||
case CMIT_FMT_MEDIUM:
|
case CMIT_FMT_MEDIUM:
|
||||||
strbuf_addf(sb, "Date: %s\n",
|
strbuf_addf(sb, "Date: %s\n",
|
||||||
|
Loading…
Reference in New Issue
Block a user