Browse Source

Export some email and pretty-printing functions

These will be used for generating the cover letter in addition to the
patch emails.

Signed-off-by: Daniel Barkalow <barkalow@iabervon.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
maint
Daniel Barkalow 17 years ago committed by Junio C Hamano
parent
commit
b02bd65f67
  1. 15
      commit.h
  2. 114
      log-tree.c
  3. 2
      log-tree.h
  4. 12
      pretty.c

15
commit.h

@ -71,6 +71,21 @@ extern void pretty_print_commit(enum cmit_fmt fmt, const struct commit*, @@ -71,6 +71,21 @@ extern void pretty_print_commit(enum cmit_fmt fmt, const struct commit*,
int abbrev, const char *subject,
const char *after_subject, enum date_mode,
int non_ascii_present);
void pp_user_info(const char *what, enum cmit_fmt fmt, struct strbuf *sb,
const char *line, enum date_mode dmode,
const char *encoding);
void pp_title_line(enum cmit_fmt fmt,
const char **msg_p,
struct strbuf *sb,
const char *subject,
const char *after_subject,
const char *encoding,
int plain_non_ascii);
void pp_remainder(enum cmit_fmt fmt,
const char **msg_p,
struct strbuf *sb,
int indent);


/** Removes the first commit from a list sorted by date, and adds all
* of its parents.

114
log-tree.c

@ -137,56 +137,11 @@ static int has_non_ascii(const char *s) @@ -137,56 +137,11 @@ static int has_non_ascii(const char *s)
return 0;
}

void show_log(struct rev_info *opt, const char *sep)
void log_write_email_headers(struct rev_info *opt, const char *name,
const char **subject_p, const char **extra_headers_p)
{
struct strbuf msgbuf;
struct log_info *log = opt->loginfo;
struct commit *commit = log->commit, *parent = log->parent;
int abbrev = opt->diffopt.abbrev;
int abbrev_commit = opt->abbrev_commit ? opt->abbrev : 40;
const char *extra;
const char *subject = NULL, *extra_headers = opt->extra_headers;

opt->loginfo = NULL;
if (!opt->verbose_header) {
if (opt->left_right) {
if (commit->object.flags & BOUNDARY)
putchar('-');
else if (commit->object.flags & SYMMETRIC_LEFT)
putchar('<');
else
putchar('>');
}
fputs(diff_unique_abbrev(commit->object.sha1, abbrev_commit), stdout);
if (opt->parents)
show_parents(commit, abbrev_commit);
show_decorations(commit);
putchar(opt->diffopt.line_termination);
return;
}

/*
* The "oneline" format has several special cases:
* - The pretty-printed commit lacks a newline at the end
* of the buffer, but we do want to make sure that we
* have a newline there. If the separator isn't already
* a newline, add an extra one.
* - unlike other log messages, the one-line format does
* not have an empty line between entries.
*/
extra = "";
if (*sep != '\n' && opt->commit_format == CMIT_FMT_ONELINE)
extra = "\n";
if (opt->shown_one && opt->commit_format != CMIT_FMT_ONELINE)
putchar(opt->diffopt.line_termination);
opt->shown_one = 1;

/*
* Print header line of header..
*/

if (opt->commit_format == CMIT_FMT_EMAIL) {
char *sha1 = sha1_to_hex(commit->object.sha1);
const char *subject = NULL;
const char *extra_headers = opt->extra_headers;
if (opt->total > 0) {
static char buffer[64];
snprintf(buffer, sizeof(buffer),
@ -205,7 +160,7 @@ void show_log(struct rev_info *opt, const char *sep) @@ -205,7 +160,7 @@ void show_log(struct rev_info *opt, const char *sep)
subject = "Subject: ";
}

printf("From %s Mon Sep 17 00:00:00 2001\n", sha1);
printf("From %s Mon Sep 17 00:00:00 2001\n", name);
if (opt->message_id)
printf("Message-Id: <%s>\n", opt->message_id);
if (opt->ref_message_id)
@ -239,11 +194,66 @@ void show_log(struct rev_info *opt, const char *sep) @@ -239,11 +194,66 @@ void show_log(struct rev_info *opt, const char *sep)
"Content-Disposition: %s;"
" filename=\"%s.diff\"\n\n",
mime_boundary_leader, opt->mime_boundary,
sha1,
name,
opt->no_inline ? "attachment" : "inline",
sha1);
name);
opt->diffopt.stat_sep = buffer;
}
*subject_p = subject;
*extra_headers_p = extra_headers;
}

void show_log(struct rev_info *opt, const char *sep)
{
struct strbuf msgbuf;
struct log_info *log = opt->loginfo;
struct commit *commit = log->commit, *parent = log->parent;
int abbrev = opt->diffopt.abbrev;
int abbrev_commit = opt->abbrev_commit ? opt->abbrev : 40;
const char *extra;
const char *subject = NULL, *extra_headers = opt->extra_headers;

opt->loginfo = NULL;
if (!opt->verbose_header) {
if (opt->left_right) {
if (commit->object.flags & BOUNDARY)
putchar('-');
else if (commit->object.flags & SYMMETRIC_LEFT)
putchar('<');
else
putchar('>');
}
fputs(diff_unique_abbrev(commit->object.sha1, abbrev_commit), stdout);
if (opt->parents)
show_parents(commit, abbrev_commit);
show_decorations(commit);
putchar(opt->diffopt.line_termination);
return;
}

/*
* The "oneline" format has several special cases:
* - The pretty-printed commit lacks a newline at the end
* of the buffer, but we do want to make sure that we
* have a newline there. If the separator isn't already
* a newline, add an extra one.
* - unlike other log messages, the one-line format does
* not have an empty line between entries.
*/
extra = "";
if (*sep != '\n' && opt->commit_format == CMIT_FMT_ONELINE)
extra = "\n";
if (opt->shown_one && opt->commit_format != CMIT_FMT_ONELINE)
putchar(opt->diffopt.line_termination);
opt->shown_one = 1;

/*
* Print header line of header..
*/

if (opt->commit_format == CMIT_FMT_EMAIL) {
log_write_email_headers(opt, sha1_to_hex(commit->object.sha1),
&subject, &extra_headers);
} else if (opt->commit_format != CMIT_FMT_USERFORMAT) {
fputs(diff_get_color_opt(&opt->diffopt, DIFF_COMMIT), stdout);
if (opt->commit_format != CMIT_FMT_ONELINE)

2
log-tree.h

@ -13,5 +13,7 @@ int log_tree_commit(struct rev_info *, struct commit *); @@ -13,5 +13,7 @@ int log_tree_commit(struct rev_info *, struct commit *);
int log_tree_opt_parse(struct rev_info *, const char **, int);
void show_log(struct rev_info *opt, const char *sep);
void show_decorations(struct commit *commit);
void log_write_email_headers(struct rev_info *opt, const char *name,
const char **subject_p, const char **extra_headers_p);

#endif

12
pretty.c

@ -110,7 +110,7 @@ needquote: @@ -110,7 +110,7 @@ needquote:
strbuf_addstr(sb, "?=");
}

static void add_user_info(const char *what, enum cmit_fmt fmt, struct strbuf *sb,
void pp_user_info(const char *what, enum cmit_fmt fmt, struct strbuf *sb,
const char *line, enum date_mode dmode,
const char *encoding)
{
@ -295,7 +295,7 @@ static void format_person_part(struct strbuf *sb, char part, @@ -295,7 +295,7 @@ static void format_person_part(struct strbuf *sb, char part,
/*
* If it does not even have a '<' and '>', that is
* quite a bogus commit author and we discard it;
* this is in line with add_user_info() that is used
* this is in line with pp_user_info() that is used
* in the normal codepath. When end points at the '<'
* that we found, it should have matching '>' later,
* which means start (beginning of email address) must
@ -643,17 +643,17 @@ static void pp_header(enum cmit_fmt fmt, @@ -643,17 +643,17 @@ static void pp_header(enum cmit_fmt fmt,
*/
if (!memcmp(line, "author ", 7)) {
strbuf_grow(sb, linelen + 80);
add_user_info("Author", fmt, sb, line + 7, dmode, encoding);
pp_user_info("Author", fmt, sb, line + 7, dmode, encoding);
}
if (!memcmp(line, "committer ", 10) &&
(fmt == CMIT_FMT_FULL || fmt == CMIT_FMT_FULLER)) {
strbuf_grow(sb, linelen + 80);
add_user_info("Commit", fmt, sb, line + 10, dmode, encoding);
pp_user_info("Commit", fmt, sb, line + 10, dmode, encoding);
}
}
}

static void pp_title_line(enum cmit_fmt fmt,
void pp_title_line(enum cmit_fmt fmt,
const char **msg_p,
struct strbuf *sb,
const char *subject,
@ -708,7 +708,7 @@ static void pp_title_line(enum cmit_fmt fmt, @@ -708,7 +708,7 @@ static void pp_title_line(enum cmit_fmt fmt,
strbuf_release(&title);
}

static void pp_remainder(enum cmit_fmt fmt,
void pp_remainder(enum cmit_fmt fmt,
const char **msg_p,
struct strbuf *sb,
int indent)

Loading…
Cancel
Save