266
strbuf_addstr(sb, "?=");
267
}
268
269
-void pp_user_info(const char *what, enum cmit_fmt fmt, struct strbuf *sb,
270
- const char *line, enum date_mode dmode,
271
- const char *encoding)
269
+void pp_user_info(const struct pretty_print_context *pp,
270
+ const char *what, struct strbuf *sb,
271
+ const char *line, const char *encoding)
272
{
273
char *date;
274
int namelen;
275
unsigned long time;
276
int tz;
277
278
- if (fmt == CMIT_FMT_ONELINE)
278
+ if (pp->fmt == CMIT_FMT_ONELINE)
279
return;
280
date = strchr(line, '>');
281
if (!date)
284
time = strtoul(date, &date, 10);
285
tz = strtol(date, NULL, 10);
286
287
- if (fmt == CMIT_FMT_EMAIL) {
287
+ if (pp->fmt == CMIT_FMT_EMAIL) {
288
char *name_tail = strchr(line, '<');
289
int display_name_length;
290
int final_line;
307
strbuf_addch(sb, '\n');
308
} else {
309
strbuf_addf(sb, "%s: %.*s%.*s\n", what,
310
- (fmt == CMIT_FMT_FULLER) ? 4 : 0,
310
+ (pp->fmt == CMIT_FMT_FULLER) ? 4 : 0,
311
" ", namelen, line);
312
}
313
- switch (fmt) {
313
+ switch (pp->fmt) {
314
case CMIT_FMT_MEDIUM:
315
- strbuf_addf(sb, "Date: %s\n", show_date(time, tz, dmode));
315
+ strbuf_addf(sb, "Date: %s\n", show_date(time, tz, pp->date_mode));
316
break;
317
case CMIT_FMT_EMAIL:
318
strbuf_addf(sb, "Date: %s\n", show_date(time, tz, DATE_RFC2822));
319
break;
320
case CMIT_FMT_FULLER:
321
- strbuf_addf(sb, "%sDate: %s\n", what, show_date(time, tz, dmode));
321
+ strbuf_addf(sb, "%sDate: %s\n", what, show_date(time, tz, pp->date_mode));
322
break;
323
default:
324
/* notin' */
349
return msg;
350
}
351
352
-static void add_merge_info(enum cmit_fmt fmt, struct strbuf *sb,
353
- const struct commit *commit, int abbrev)
352
+static void add_merge_info(const struct pretty_print_context *pp,
353
+ struct strbuf *sb, const struct commit *commit)
354
{
355
struct commit_list *parent = commit->parents;
356
357
- if ((fmt == CMIT_FMT_ONELINE) || (fmt == CMIT_FMT_EMAIL) ||
357
+ if ((pp->fmt == CMIT_FMT_ONELINE) || (pp->fmt == CMIT_FMT_EMAIL) ||
358
!parent || !parent->next)
359
return;
360
363
while (parent) {
364
struct commit *p = parent->item;
365
const char *hex = NULL;
366
- if (abbrev)
367
- hex = find_unique_abbrev(p->object.sha1, abbrev);
366
+ if (pp->abbrev)
367
+ hex = find_unique_abbrev(p->object.sha1, pp->abbrev);
368
if (!hex)
369
hex = sha1_to_hex(p->object.sha1);
370
parent = parent->next;
1061
free(context.message);
1062
}
1063
1064
-static void pp_header(enum cmit_fmt fmt,
1065
- int abbrev,
1066
- enum date_mode dmode,
1064
+static void pp_header(const struct pretty_print_context *pp,
1065
const char *encoding,
1066
const struct commit *commit,
1067
const char **msg_p,
1081
/* End of header */
1082
return;
1083
1086
- if (fmt == CMIT_FMT_RAW) {
1084
+ if (pp->fmt == CMIT_FMT_RAW) {
1085
strbuf_add(sb, line, linelen);
1086
continue;
1087
}
1101
;
1102
/* with enough slop */
1103
strbuf_grow(sb, num * 50 + 20);
1106
- add_merge_info(fmt, sb, commit, abbrev);
1104
+ add_merge_info(pp, sb, commit);
1105
parents_shown = 1;
1106
}
1107
1112
*/
1113
if (!memcmp(line, "author ", 7)) {
1114
strbuf_grow(sb, linelen + 80);
1117
- pp_user_info("Author", fmt, sb, line + 7, dmode, encoding);
1115
+ pp_user_info(pp, "Author", sb, line + 7, encoding);
1116
}
1117
if (!memcmp(line, "committer ", 10) &&
1120
- (fmt == CMIT_FMT_FULL || fmt == CMIT_FMT_FULLER)) {
1118
+ (pp->fmt == CMIT_FMT_FULL || pp->fmt == CMIT_FMT_FULLER)) {
1119
strbuf_grow(sb, linelen + 80);
1122
- pp_user_info("Commit", fmt, sb, line + 10, dmode, encoding);
1120
+ pp_user_info(pp, "Commit", sb, line + 10, encoding);
1121
}
1122
}
1123
}
1124
1127
-void pp_title_line(enum cmit_fmt fmt,
1125
+void pp_title_line(const struct pretty_print_context *pp,
1126
const char **msg_p,
1127
struct strbuf *sb,
1130
- const char *subject,
1131
- const char *after_subject,
1128
const char *encoding,
1129
int need_8bit_cte)
1130
{
1134
*msg_p = format_subject(&title, *msg_p, " ");
1135
1136
strbuf_grow(sb, title.len + 1024);
1141
- if (subject) {
1142
- strbuf_addstr(sb, subject);
1137
+ if (pp->subject) {
1138
+ strbuf_addstr(sb, pp->subject);
1139
add_rfc2047(sb, title.buf, title.len, encoding);
1140
} else {
1141
strbuf_addbuf(sb, &title);
1149
"Content-Transfer-Encoding: 8bit\n";
1150
strbuf_addf(sb, header_fmt, encoding);
1151
}
1156
- if (after_subject) {
1157
- strbuf_addstr(sb, after_subject);
1152
+ if (pp->after_subject) {
1153
+ strbuf_addstr(sb, pp->after_subject);
1154
}
1159
- if (fmt == CMIT_FMT_EMAIL) {
1155
+ if (pp->fmt == CMIT_FMT_EMAIL) {
1156
strbuf_addch(sb, '\n');
1157
}
1158
strbuf_release(&title);
1159
}
1160
1165
-void pp_remainder(enum cmit_fmt fmt,
1161
+void pp_remainder(const struct pretty_print_context *pp,
1162
const char **msg_p,
1163
struct strbuf *sb,
1164
int indent)
1175
if (is_empty_line(line, &linelen)) {
1176
if (first)
1177
continue;
1182
- if (fmt == CMIT_FMT_SHORT)
1178
+ if (pp->fmt == CMIT_FMT_SHORT)
1179
break;
1180
}
1181
first = 0;
1200
return logmsg_reencode(commit, encoding);
1201
}
1202
1207
-void pretty_print_commit(enum cmit_fmt fmt, const struct commit *commit,
1208
- struct strbuf *sb,
1209
- const struct pretty_print_context *context)
1203
+void pretty_print_commit(const struct pretty_print_context *pp,
1204
+ const struct commit *commit,
1205
+ struct strbuf *sb)
1206
{
1207
unsigned long beginning_of_body;
1208
int indent = 4;
1209
const char *msg = commit->buffer;
1210
char *reencoded;
1211
const char *encoding;
1216
- int need_8bit_cte = context->need_8bit_cte;
1212
+ int need_8bit_cte = pp->need_8bit_cte;
1213
1218
- if (fmt == CMIT_FMT_USERFORMAT) {
1219
- format_commit_message(commit, user_format, sb, context);
1214
+ if (pp->fmt == CMIT_FMT_USERFORMAT) {
1215
+ format_commit_message(commit, user_format, sb, pp);
1216
return;
1217
}
1218
1221
msg = reencoded;
1222
}
1223
1228
- if (fmt == CMIT_FMT_ONELINE || fmt == CMIT_FMT_EMAIL)
1224
+ if (pp->fmt == CMIT_FMT_ONELINE || pp->fmt == CMIT_FMT_EMAIL)
1225
indent = 0;
1226
1227
/*
1228
* We need to check and emit Content-type: to mark it
1229
* as 8-bit if we haven't done so.
1230
*/
1235
- if (fmt == CMIT_FMT_EMAIL && need_8bit_cte == 0) {
1231
+ if (pp->fmt == CMIT_FMT_EMAIL && need_8bit_cte == 0) {
1232
int i, ch, in_body;
1233
1234
for (in_body = i = 0; (ch = msg[i]); i++) {
1247
}
1248
}
1249
1254
- pp_header(fmt, context->abbrev, context->date_mode, encoding,
1255
- commit, &msg, sb);
1256
- if (fmt != CMIT_FMT_ONELINE && !context->subject) {
1250
+ pp_header(pp, encoding, commit, &msg, sb);
1251
+ if (pp->fmt != CMIT_FMT_ONELINE && !pp->subject) {
1252
strbuf_addch(sb, '\n');
1253
}
1254
1256
msg = skip_empty_lines(msg);
1257
1258
/* These formats treat the title line specially. */
1264
- if (fmt == CMIT_FMT_ONELINE || fmt == CMIT_FMT_EMAIL)
1265
- pp_title_line(fmt, &msg, sb, context->subject,
1266
- context->after_subject, encoding, need_8bit_cte);
1259
+ if (pp->fmt == CMIT_FMT_ONELINE || pp->fmt == CMIT_FMT_EMAIL)
1260
+ pp_title_line(pp, &msg, sb, encoding, need_8bit_cte);
1261
1262
beginning_of_body = sb->len;
1269
- if (fmt != CMIT_FMT_ONELINE)
1270
- pp_remainder(fmt, &msg, sb, indent);
1263
+ if (pp->fmt != CMIT_FMT_ONELINE)
1264
+ pp_remainder(pp, &msg, sb, indent);
1265
strbuf_rtrim(sb);
1266
1267
/* Make sure there is an EOLN for the non-oneline case */
1274
- if (fmt != CMIT_FMT_ONELINE)
1268
+ if (pp->fmt != CMIT_FMT_ONELINE)
1269
strbuf_addch(sb, '\n');
1270
1271
/*
1273
* format. Make sure we did not strip the blank line
1274
* between the header and the body.
1275
*/
1282
- if (fmt == CMIT_FMT_EMAIL && sb->len <= beginning_of_body)
1276
+ if (pp->fmt == CMIT_FMT_EMAIL && sb->len <= beginning_of_body)
1277
strbuf_addch(sb, '\n');
1278
1285
- if (context->show_notes)
1279
+ if (pp->show_notes)
1280
format_display_notes(commit->object.sha1, sb, encoding,
1281
NOTES_SHOW_HEADER | NOTES_INDENT);
1282
1287
struct strbuf *sb)
1288
{
1289
struct pretty_print_context pp = {0};
1296
- pretty_print_commit(fmt, commit, sb, &pp);
1290
+ pp.fmt = fmt;
1291
+ pretty_print_commit(&pp, commit, sb);
1292
}