log-tree.c 17.2 KB
Newer Older
1 2 3
#include "cache.h"
#include "diff.h"
#include "commit.h"
4
#include "tag.h"
5
#include "graph.h"
6
#include "log-tree.h"
7
#include "reflog-walk.h"
8
#include "refs.h"
9
#include "string-list.h"
10
#include "color.h"
11

12 13
struct decoration name_decoration = { "object names" };

14 15 16 17 18 19 20 21 22
enum decoration_type {
	DECORATION_NONE = 0,
	DECORATION_REF_LOCAL,
	DECORATION_REF_REMOTE,
	DECORATION_REF_TAG,
	DECORATION_REF_STASH,
	DECORATION_REF_HEAD,
};

23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
static char decoration_colors[][COLOR_MAXLEN] = {
	GIT_COLOR_RESET,
	GIT_COLOR_BOLD_GREEN,	/* REF_LOCAL */
	GIT_COLOR_BOLD_RED,	/* REF_REMOTE */
	GIT_COLOR_BOLD_YELLOW,	/* REF_TAG */
	GIT_COLOR_BOLD_MAGENTA,	/* REF_STASH */
	GIT_COLOR_BOLD_CYAN,	/* REF_HEAD */
};

static const char *decorate_get_color(int decorate_use_color, enum decoration_type ix)
{
	if (decorate_use_color)
		return decoration_colors[ix];
	return "";
}

39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
static int parse_decorate_color_slot(const char *slot)
{
	/*
	 * We're comparing with 'ignore-case' on
	 * (because config.c sets them all tolower),
	 * but let's match the letters in the literal
	 * string values here with how they are
	 * documented in Documentation/config.txt, for
	 * consistency.
	 *
	 * We love being consistent, don't we?
	 */
	if (!strcasecmp(slot, "branch"))
		return DECORATION_REF_LOCAL;
	if (!strcasecmp(slot, "remoteBranch"))
		return DECORATION_REF_REMOTE;
	if (!strcasecmp(slot, "tag"))
		return DECORATION_REF_TAG;
	if (!strcasecmp(slot, "stash"))
		return DECORATION_REF_STASH;
	if (!strcasecmp(slot, "HEAD"))
		return DECORATION_REF_HEAD;
	return -1;
}

int parse_decorate_color_config(const char *var, const int ofs, const char *value)
{
	int slot = parse_decorate_color_slot(var + ofs);
	if (slot < 0)
		return 0;
	if (!value)
		return config_error_nonbool(var);
	color_parse(value, var, decoration_colors[slot]);
	return 0;
}

75 76 77 78 79 80 81
/*
 * log-tree.c uses DIFF_OPT_TST for determining whether to use color
 * for showing the commit sha1, use the same check for --decorate
 */
#define decorate_get_color_opt(o, ix) \
	decorate_get_color(DIFF_OPT_TST((o), COLOR_DIFF), ix)

82
static void add_name_decoration(enum decoration_type type, const char *name, struct object *obj)
83 84
{
	int nlen = strlen(name);
85 86 87
	struct name_decoration *res = xmalloc(sizeof(struct name_decoration) + nlen);
	memcpy(res->name, name, nlen + 1);
	res->type = type;
88 89 90 91 92 93
	res->next = add_decoration(&name_decoration, obj, res);
}

static int add_ref_decoration(const char *refname, const unsigned char *sha1, int flags, void *cb_data)
{
	struct object *obj = parse_object(sha1);
94
	enum decoration_type type = DECORATION_NONE;
95 96
	if (!obj)
		return 0;
97 98 99 100 101 102 103 104 105 106 107 108

	if (!prefixcmp(refname, "refs/heads"))
		type = DECORATION_REF_LOCAL;
	else if (!prefixcmp(refname, "refs/remotes"))
		type = DECORATION_REF_REMOTE;
	else if (!prefixcmp(refname, "refs/tags"))
		type = DECORATION_REF_TAG;
	else if (!prefixcmp(refname, "refs/stash"))
		type = DECORATION_REF_STASH;
	else if (!prefixcmp(refname, "HEAD"))
		type = DECORATION_REF_HEAD;

109 110
	if (!cb_data || *(int *)cb_data == DECORATE_SHORT_REFS)
		refname = prettify_refname(refname);
111
	add_name_decoration(type, refname, obj);
112 113 114 115
	while (obj->type == OBJ_TAG) {
		obj = ((struct tag *)obj)->tagged;
		if (!obj)
			break;
116
		add_name_decoration(DECORATION_REF_TAG, refname, obj);
117 118 119 120
	}
	return 0;
}

121
void load_ref_decorations(int flags)
122 123 124 125
{
	static int loaded;
	if (!loaded) {
		loaded = 1;
126
		for_each_ref(add_ref_decoration, &flags);
T
Thomas Rast 已提交
127
		head_ref(add_ref_decoration, &flags);
128 129 130
	}
}

131 132 133 134 135
static void show_parents(struct commit *commit, int abbrev)
{
	struct commit_list *p;
	for (p = commit->parents; p ; p = p->next) {
		struct commit *parent = p->item;
136
		printf(" %s", find_unique_abbrev(parent->object.sha1, abbrev));
137 138 139
	}
}

140
void show_decorations(struct rev_info *opt, struct commit *commit)
141 142 143
{
	const char *prefix;
	struct name_decoration *decoration;
144 145 146 147
	const char *color_commit =
		diff_get_color_opt(&opt->diffopt, DIFF_COMMIT);
	const char *color_reset =
		decorate_get_color_opt(&opt->diffopt, DECORATION_NONE);
148

149
	if (opt->show_source && commit->util)
150
		printf("\t%s", (char *) commit->util);
151 152
	if (!opt->show_decorations)
		return;
153 154 155 156 157
	decoration = lookup_decoration(&name_decoration, &commit->object);
	if (!decoration)
		return;
	prefix = " (";
	while (decoration) {
158
		printf("%s", prefix);
159 160
		fputs(decorate_get_color_opt(&opt->diffopt, decoration->type),
		      stdout);
161
		if (decoration->type == DECORATION_REF_TAG)
162
			fputs("tag: ", stdout);
163
		printf("%s", decoration->name);
164 165
		fputs(color_reset, stdout);
		fputs(color_commit, stdout);
166 167 168 169 170 171
		prefix = ", ";
		decoration = decoration->next;
	}
	putchar(')');
}

172 173 174 175 176 177
/*
 * Search for "^[-A-Za-z]+: [^@]+@" pattern. It usually matches
 * Signed-off-by: and Acked-by: lines.
 */
static int detect_any_signoff(char *letter, int size)
{
178
	char *cp;
179 180 181 182 183 184
	int seen_colon = 0;
	int seen_at = 0;
	int seen_name = 0;
	int seen_head = 0;

	cp = letter + size;
185
	while (letter <= --cp && *cp == '\n')
186 187 188
		continue;

	while (letter <= cp) {
189
		char ch = *cp--;
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218
		if (ch == '\n')
			break;

		if (!seen_at) {
			if (ch == '@')
				seen_at = 1;
			continue;
		}
		if (!seen_colon) {
			if (ch == '@')
				return 0;
			else if (ch == ':')
				seen_colon = 1;
			else
				seen_name = 1;
			continue;
		}
		if (('A' <= ch && ch <= 'Z') ||
		    ('a' <= ch && ch <= 'z') ||
		    ch == '-') {
			seen_head = 1;
			continue;
		}
		/* no empty last line doesn't match */
		return 0;
	}
	return seen_head && seen_name;
}

219
static void append_signoff(struct strbuf *sb, const char *signoff)
J
Junio C Hamano 已提交
220 221
{
	static const char signed_off_by[] = "Signed-off-by: ";
222
	size_t signoff_len = strlen(signoff);
223
	int has_signoff = 0;
224
	char *cp;
J
Junio C Hamano 已提交
225

226
	cp = sb->buf;
J
Junio C Hamano 已提交
227 228

	/* First see if we already have the sign-off by the signer */
229 230 231 232
	while ((cp = strstr(cp, signed_off_by))) {

		has_signoff = 1;

J
Junio C Hamano 已提交
233
		cp += strlen(signed_off_by);
234
		if (cp + signoff_len >= sb->buf + sb->len)
235 236 237 238 239 240
			break;
		if (strncmp(cp, signoff, signoff_len))
			continue;
		if (!isspace(cp[signoff_len]))
			continue;
		/* we already have him */
241
		return;
J
Junio C Hamano 已提交
242 243
	}

244
	if (!has_signoff)
245
		has_signoff = detect_any_signoff(sb->buf, sb->len);
246 247

	if (!has_signoff)
248
		strbuf_addch(sb, '\n');
249

250 251 252
	strbuf_addstr(sb, signed_off_by);
	strbuf_add(sb, signoff, signoff_len);
	strbuf_addch(sb, '\n');
J
Junio C Hamano 已提交
253 254
}

255 256 257 258 259 260 261 262 263 264
static unsigned int digits_in_number(unsigned int number)
{
	unsigned int i = 10, result = 1;
	while (i <= number) {
		i *= 10;
		result++;
	}
	return result;
}

265 266 267 268 269 270 271 272
void get_patch_filename(struct commit *commit, int nr, const char *suffix,
			struct strbuf *buf)
{
	int suffix_len = strlen(suffix) + 1;
	int start_len = buf->len;

	strbuf_addf(buf, commit ? "%04d-" : "%d", nr);
	if (commit) {
273
		int max_len = start_len + FORMAT_PATCH_NAME_MAX - suffix_len;
274 275
		struct pretty_print_context ctx = {0};
		ctx.date_mode = DATE_NORMAL;
276

277
		format_commit_message(commit, "%f", buf, &ctx);
278 279 280
		if (max_len < buf->len)
			strbuf_setlen(buf, max_len);
		strbuf_addstr(buf, suffix);
281 282 283
	}
}

284
void log_write_email_headers(struct rev_info *opt, struct commit *commit,
J
Junio C Hamano 已提交
285 286 287
			     const char **subject_p,
			     const char **extra_headers_p,
			     int *need_8bit_cte_p)
288 289 290
{
	const char *subject = NULL;
	const char *extra_headers = opt->extra_headers;
291
	const char *name = sha1_to_hex(commit->object.sha1);
J
Junio C Hamano 已提交
292 293

	*need_8bit_cte_p = 0; /* unknown */
294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312
	if (opt->total > 0) {
		static char buffer[64];
		snprintf(buffer, sizeof(buffer),
			 "Subject: [%s %0*d/%d] ",
			 opt->subject_prefix,
			 digits_in_number(opt->total),
			 opt->nr, opt->total);
		subject = buffer;
	} else if (opt->total == 0 && opt->subject_prefix && *opt->subject_prefix) {
		static char buffer[256];
		snprintf(buffer, sizeof(buffer),
			 "Subject: [%s] ",
			 opt->subject_prefix);
		subject = buffer;
	} else {
		subject = "Subject: ";
	}

	printf("From %s Mon Sep 17 00:00:00 2001\n", name);
313 314
	graph_show_oneline(opt->graph);
	if (opt->message_id) {
315
		printf("Message-Id: <%s>\n", opt->message_id);
316 317
		graph_show_oneline(opt->graph);
	}
318 319 320 321 322 323 324
	if (opt->ref_message_ids && opt->ref_message_ids->nr > 0) {
		int i, n;
		n = opt->ref_message_ids->nr;
		printf("In-Reply-To: <%s>\n", opt->ref_message_ids->items[n-1].string);
		for (i = 0; i < n; i++)
			printf("%s<%s>\n", (i > 0 ? "\t" : "References: "),
			       opt->ref_message_ids->items[i].string);
325 326
		graph_show_oneline(opt->graph);
	}
327 328 329
	if (opt->mime_boundary) {
		static char subject_buffer[1024];
		static char buffer[1024];
330
		struct strbuf filename =  STRBUF_INIT;
J
Junio C Hamano 已提交
331
		*need_8bit_cte_p = -1; /* NEVER */
332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348
		snprintf(subject_buffer, sizeof(subject_buffer) - 1,
			 "%s"
			 "MIME-Version: 1.0\n"
			 "Content-Type: multipart/mixed;"
			 " boundary=\"%s%s\"\n"
			 "\n"
			 "This is a multi-part message in MIME "
			 "format.\n"
			 "--%s%s\n"
			 "Content-Type: text/plain; "
			 "charset=UTF-8; format=fixed\n"
			 "Content-Transfer-Encoding: 8bit\n\n",
			 extra_headers ? extra_headers : "",
			 mime_boundary_leader, opt->mime_boundary,
			 mime_boundary_leader, opt->mime_boundary);
		extra_headers = subject_buffer;

349 350
		get_patch_filename(opt->numbered_files ? NULL : commit, opt->nr,
				    opt->patch_suffix, &filename);
351
		snprintf(buffer, sizeof(buffer) - 1,
352
			 "\n--%s%s\n"
353
			 "Content-Type: text/x-patch;"
354
			 " name=\"%s\"\n"
355 356
			 "Content-Transfer-Encoding: 8bit\n"
			 "Content-Disposition: %s;"
357
			 " filename=\"%s\"\n\n",
358
			 mime_boundary_leader, opt->mime_boundary,
359
			 filename.buf,
360
			 opt->no_inline ? "attachment" : "inline",
361
			 filename.buf);
362
		opt->diffopt.stat_sep = buffer;
363
		strbuf_release(&filename);
364 365 366 367 368
	}
	*subject_p = subject;
	*extra_headers_p = extra_headers;
}

369
void show_log(struct rev_info *opt)
L
Linus Torvalds 已提交
370
{
371
	struct strbuf msgbuf = STRBUF_INIT;
T
Timo Hirvonen 已提交
372
	struct log_info *log = opt->loginfo;
L
Linus Torvalds 已提交
373 374
	struct commit *commit = log->commit, *parent = log->parent;
	int abbrev_commit = opt->abbrev_commit ? opt->abbrev : 40;
375 376
	const char *extra_headers = opt->extra_headers;
	struct pretty_print_context ctx = {0};
L
Linus Torvalds 已提交
377 378

	opt->loginfo = NULL;
379
	ctx.show_notes = opt->show_notes;
L
Linus Torvalds 已提交
380
	if (!opt->verbose_header) {
381 382
		graph_show_commit(opt->graph);

383 384 385 386 387 388 389 390 391 392 393
		if (!opt->graph) {
			if (commit->object.flags & BOUNDARY)
				putchar('-');
			else if (commit->object.flags & UNINTERESTING)
				putchar('^');
			else if (opt->left_right) {
				if (commit->object.flags & SYMMETRIC_LEFT)
					putchar('<');
				else
					putchar('>');
			}
394
		}
395
		fputs(find_unique_abbrev(commit->object.sha1, abbrev_commit), stdout);
396
		if (opt->print_parents)
397
			show_parents(commit, abbrev_commit);
398
		show_decorations(opt, commit);
399 400 401 402
		if (opt->graph && !graph_is_commit_finished(opt->graph)) {
			putchar('\n');
			graph_show_remainder(opt->graph);
		}
403
		putchar(opt->diffopt.line_termination);
L
Linus Torvalds 已提交
404 405 406 407
		return;
	}

	/*
J
Jeff King 已提交
408 409
	 * If use_terminator is set, we already handled any record termination
	 * at the end of the last record.
410 411
	 * Otherwise, add a diffopt.line_termination character before all
	 * entries but the first.  (IOW, as a separator between entries)
L
Linus Torvalds 已提交
412
	 */
413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428
	if (opt->shown_one && !opt->use_terminator) {
		/*
		 * If entries are separated by a newline, the output
		 * should look human-readable.  If the last entry ended
		 * with a newline, print the graph output before this
		 * newline.  Otherwise it will end up as a completely blank
		 * line and will look like a gap in the graph.
		 *
		 * If the entry separator is not a newline, the output is
		 * primarily intended for programmatic consumption, and we
		 * never want the extra graph output before the entry
		 * separator.
		 */
		if (opt->diffopt.line_termination == '\n' &&
		    !opt->missing_newline)
			graph_show_padding(opt->graph);
L
Linus Torvalds 已提交
429
		putchar(opt->diffopt.line_termination);
430
	}
L
Linus Torvalds 已提交
431 432
	opt->shown_one = 1;

433 434 435 436 437 438
	/*
	 * If the history graph was requested,
	 * print the graph, up to this commit's line
	 */
	graph_show_commit(opt->graph);

L
Linus Torvalds 已提交
439 440 441
	/*
	 * Print header line of header..
	 */
442

443
	if (opt->commit_format == CMIT_FMT_EMAIL) {
444 445
		log_write_email_headers(opt, commit, &ctx.subject, &extra_headers,
					&ctx.need_8bit_cte);
446
	} else if (opt->commit_format != CMIT_FMT_USERFORMAT) {
447
		fputs(diff_get_color_opt(&opt->diffopt, DIFF_COMMIT), stdout);
448 449
		if (opt->commit_format != CMIT_FMT_ONELINE)
			fputs("commit ", stdout);
450 451 452 453 454 455 456 457 458 459 460 461

		if (!opt->graph) {
			if (commit->object.flags & BOUNDARY)
				putchar('-');
			else if (commit->object.flags & UNINTERESTING)
				putchar('^');
			else if (opt->left_right) {
				if (commit->object.flags & SYMMETRIC_LEFT)
					putchar('<');
				else
					putchar('>');
			}
462
		}
463
		fputs(find_unique_abbrev(commit->object.sha1, abbrev_commit),
464
		      stdout);
465
		if (opt->print_parents)
466
			show_parents(commit, abbrev_commit);
J
Junio C Hamano 已提交
467
		if (parent)
468
			printf(" (from %s)",
469
			       find_unique_abbrev(parent->object.sha1,
470
						  abbrev_commit));
471
		show_decorations(opt, commit);
472
		printf("%s", diff_get_color_opt(&opt->diffopt, DIFF_RESET));
473 474 475 476 477 478
		if (opt->commit_format == CMIT_FMT_ONELINE) {
			putchar(' ');
		} else {
			putchar('\n');
			graph_show_oneline(opt->graph);
		}
479
		if (opt->reflog_info) {
480 481 482 483 484 485
			/*
			 * setup_revisions() ensures that opt->reflog_info
			 * and opt->graph cannot both be set,
			 * so we don't need to worry about printing the
			 * graph info here.
			 */
486
			show_reflog_message(opt->reflog_info,
487
				    opt->commit_format == CMIT_FMT_ONELINE,
J
Jeff King 已提交
488 489 490
				    opt->date_mode_explicit ?
					opt->date_mode :
					DATE_NORMAL);
491
			if (opt->commit_format == CMIT_FMT_ONELINE)
492 493
				return;
		}
494
	}
L
Linus Torvalds 已提交
495

496 497 498
	if (!commit->buffer)
		return;

L
Linus Torvalds 已提交
499 500 501
	/*
	 * And then the pretty-printed message itself
	 */
502 503 504 505 506
	if (ctx.need_8bit_cte >= 0)
		ctx.need_8bit_cte = has_non_ascii(opt->add_signoff);
	ctx.date_mode = opt->date_mode;
	ctx.abbrev = opt->diffopt.abbrev;
	ctx.after_subject = extra_headers;
507
	ctx.preserve_subject = opt->preserve_subject;
508
	ctx.reflog_info = opt->reflog_info;
509 510
	ctx.fmt = opt->commit_format;
	pretty_print_commit(&ctx, commit, &msgbuf);
J
Junio C Hamano 已提交
511 512

	if (opt->add_signoff)
513
		append_signoff(&msgbuf, opt->add_signoff);
514
	if (opt->show_log_size) {
515
		printf("log size %i\n", (int)msgbuf.len);
516 517
		graph_show_oneline(opt->graph);
	}
518

519 520 521 522 523 524 525 526 527 528 529 530
	/*
	 * Set opt->missing_newline if msgbuf doesn't
	 * end in a newline (including if it is empty)
	 */
	if (!msgbuf.len || msgbuf.buf[msgbuf.len - 1] != '\n')
		opt->missing_newline = 1;
	else
		opt->missing_newline = 0;

	if (opt->graph)
		graph_show_commit_msg(opt->graph, &msgbuf);
	else
531
		fwrite(msgbuf.buf, sizeof(char), msgbuf.len, stdout);
532 533 534
	if (opt->use_terminator) {
		if (!opt->missing_newline)
			graph_show_padding(opt->graph);
535
		putchar('\n');
536 537
	}

538
	strbuf_release(&msgbuf);
L
Linus Torvalds 已提交
539 540
}

541
int log_tree_diff_flush(struct rev_info *opt)
542 543
{
	diffcore_std(&opt->diffopt);
L
Linus Torvalds 已提交
544

545 546 547 548 549 550 551
	if (diff_queue_is_empty()) {
		int saved_fmt = opt->diffopt.output_format;
		opt->diffopt.output_format = DIFF_FORMAT_NO_OUTPUT;
		diff_flush(&opt->diffopt);
		opt->diffopt.output_format = saved_fmt;
		return 0;
	}
L
Linus Torvalds 已提交
552

553 554 555 556 557 558
	if (opt->loginfo && !opt->no_commit_id) {
		/* When showing a verbose header (i.e. log message),
		 * and not in --pretty=oneline format, we would want
		 * an extra newline between the end of log and the
		 * output for readability.
		 */
559
		show_log(opt);
560 561
		if ((opt->diffopt.output_format & ~DIFF_FORMAT_NO_OUTPUT) &&
		    opt->verbose_header &&
562 563 564
		    opt->commit_format != CMIT_FMT_ONELINE) {
			int pch = DIFF_FORMAT_DIFFSTAT | DIFF_FORMAT_PATCH;
			if ((pch & opt->diffopt.output_format) == pch)
L
Linus Torvalds 已提交
565
				printf("---");
566 567 568 569 570 571
			if (opt->diffopt.output_prefix) {
				struct strbuf *msg = NULL;
				msg = opt->diffopt.output_prefix(&opt->diffopt,
					opt->diffopt.output_prefix_data);
				fwrite(msg->buf, msg->len, 1, stdout);
			}
L
Linus Torvalds 已提交
572
			putchar('\n');
573 574
		}
	}
575 576 577 578
	diff_flush(&opt->diffopt);
	return 1;
}

579
static int do_diff_combined(struct rev_info *opt, struct commit *commit)
580 581 582
{
	unsigned const char *sha1 = commit->object.sha1;

L
Linus Torvalds 已提交
583 584
	diff_tree_combined_merge(sha1, opt->dense_combined_merges, opt);
	return !opt->loginfo;
585 586
}

L
Linus Torvalds 已提交
587 588 589 590 591 592
/*
 * Show the diff of a commit.
 *
 * Return true if we printed any log info messages
 */
static int log_tree_diff(struct rev_info *opt, struct commit *commit, struct log_info *log)
593
{
L
Linus Torvalds 已提交
594
	int showed_log;
595 596 597
	struct commit_list *parents;
	unsigned const char *sha1 = commit->object.sha1;

598
	if (!opt->diff && !DIFF_OPT_TST(&opt->diffopt, EXIT_WITH_STATUS))
L
Linus Torvalds 已提交
599 600
		return 0;

601
	/* Root commit? */
L
Linus Torvalds 已提交
602 603
	parents = commit->parents;
	if (!parents) {
R
Rene Scharfe 已提交
604 605 606 607
		if (opt->show_root_diff) {
			diff_root_tree_sha1(sha1, "", &opt->diffopt);
			log_tree_diff_flush(opt);
		}
L
Linus Torvalds 已提交
608
		return !opt->loginfo;
609 610 611
	}

	/* More than one parent? */
L
Linus Torvalds 已提交
612
	if (parents && parents->next) {
613 614 615 616
		if (opt->ignore_merges)
			return 0;
		else if (opt->combine_merges)
			return do_diff_combined(opt, commit);
617 618 619 620 621 622 623 624 625 626
		else if (opt->first_parent_only) {
			/*
			 * Generate merge log entry only for the first
			 * parent, showing summary diff of the others
			 * we merged _in_.
			 */
			diff_tree_sha1(parents->item->object.sha1, sha1, "", &opt->diffopt);
			log_tree_diff_flush(opt);
			return !opt->loginfo;
		}
L
Linus Torvalds 已提交
627 628 629

		/* If we show individual diffs, show the parent info */
		log->parent = parents->item;
630 631
	}

L
Linus Torvalds 已提交
632 633
	showed_log = 0;
	for (;;) {
634 635
		struct commit *parent = parents->item;

L
Linus Torvalds 已提交
636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653
		diff_tree_sha1(parent->object.sha1, sha1, "", &opt->diffopt);
		log_tree_diff_flush(opt);

		showed_log |= !opt->loginfo;

		/* Set up the log info for the next parent, if any.. */
		parents = parents->next;
		if (!parents)
			break;
		log->parent = parents->item;
		opt->loginfo = log;
	}
	return showed_log;
}

int log_tree_commit(struct rev_info *opt, struct commit *commit)
{
	struct log_info log;
654
	int shown;
L
Linus Torvalds 已提交
655 656 657 658 659

	log.commit = commit;
	log.parent = NULL;
	opt->loginfo = &log;

660 661
	shown = log_tree_diff(opt, commit, &log);
	if (!shown && opt->loginfo && opt->always_show_header) {
L
Linus Torvalds 已提交
662
		log.parent = NULL;
663
		show_log(opt);
664
		shown = 1;
665
	}
L
Linus Torvalds 已提交
666
	opt->loginfo = NULL;
667
	maybe_flush_or_die(stdout, "stdout");
668
	return shown;
669
}