6 int log_tree_diff_flush(struct rev_info *opt)
8 diffcore_std(&opt->diffopt);
9 if (diff_queue_is_empty()) {
10 int saved_fmt = opt->diffopt.output_format;
11 opt->diffopt.output_format = DIFF_FORMAT_NO_OUTPUT;
12 diff_flush(&opt->diffopt);
13 opt->diffopt.output_format = saved_fmt;
17 if (!opt->no_commit_id)
18 printf("%s%c", opt->header,
19 opt->diffopt.line_termination);
22 diff_flush(&opt->diffopt);
26 static int diff_root_tree(struct rev_info *opt,
27 const unsigned char *new, const char *base)
31 struct tree_desc empty, real;
33 tree = read_object_with_reference(new, tree_type, &real.size, NULL);
35 die("unable to read root tree (%s)", sha1_to_hex(new));
40 retval = diff_tree(&empty, &real, base, &opt->diffopt);
42 log_tree_diff_flush(opt);
46 static const char *generate_header(struct rev_info *opt,
47 const unsigned char *commit_sha1,
48 const unsigned char *parent_sha1,
49 const struct commit *commit)
51 static char this_header[16384];
54 int abbrev = opt->diffopt.abbrev;
55 const char *msg = commit->buffer;
57 if (opt->use_precomputed_header)
58 return opt->use_precomputed_header;
60 if (!opt->verbose_header)
61 return sha1_to_hex(commit_sha1);
65 offset = sprintf(this_header, "%s%s ",
67 diff_unique_abbrev(commit_sha1, abbrev));
68 if (commit_sha1 != parent_sha1)
69 offset += sprintf(this_header + offset, "(from %s)\n",
71 ? diff_unique_abbrev(parent_sha1, abbrev)
74 offset += sprintf(this_header + offset, "(from parents)\n");
75 offset += pretty_print_commit(opt->commit_format, commit, len,
77 sizeof(this_header) - offset, abbrev);
78 if (opt->always_show_header) {
85 static int do_diff_combined(struct rev_info *opt, struct commit *commit)
87 unsigned const char *sha1 = commit->object.sha1;
89 opt->header = generate_header(opt, sha1, sha1, commit);
90 opt->header = diff_tree_combined_merge(sha1, opt->header,
91 opt->dense_combined_merges,
93 if (!opt->header && opt->verbose_header)
94 opt->header_prefix = "\ndiff-tree ";
98 int log_tree_commit(struct rev_info *opt, struct commit *commit)
100 struct commit_list *parents;
101 unsigned const char *sha1 = commit->object.sha1;
104 if (opt->show_root_diff && !commit->parents) {
105 opt->header = generate_header(opt, sha1, NULL, commit);
106 diff_root_tree(opt, sha1, "");
109 /* More than one parent? */
110 if (commit->parents && commit->parents->next) {
111 if (opt->ignore_merges)
113 else if (opt->combine_merges)
114 return do_diff_combined(opt, commit);
117 for (parents = commit->parents; parents; parents = parents->next) {
118 struct commit *parent = parents->item;
119 unsigned const char *psha1 = parent->object.sha1;
120 opt->header = generate_header(opt, sha1, psha1, commit);
121 diff_tree_sha1(psha1, sha1, "", &opt->diffopt);
122 log_tree_diff_flush(opt);
124 if (!opt->header && opt->verbose_header)
125 opt->header_prefix = "\ndiff-tree ";