]>
git.ipfire.org Git - thirdparty/git.git/blob - log-tree.c
6 static void show_parents(struct commit
*commit
, int abbrev
)
9 for (p
= commit
->parents
; p
; p
= p
->next
) {
10 struct commit
*parent
= p
->item
;
11 printf(" %s", diff_unique_abbrev(parent
->object
.sha1
, abbrev
));
15 void show_log(struct rev_info
*opt
, struct log_info
*log
, const char *sep
)
17 static char this_header
[16384];
18 struct commit
*commit
= log
->commit
, *parent
= log
->parent
;
19 int abbrev
= opt
->diffopt
.abbrev
;
20 int abbrev_commit
= opt
->abbrev_commit
? opt
->abbrev
: 40;
25 if (!opt
->verbose_header
) {
26 fputs(diff_unique_abbrev(commit
->object
.sha1
, abbrev_commit
), stdout
);
28 show_parents(commit
, abbrev_commit
);
34 * The "oneline" format has several special cases:
35 * - The pretty-printed commit lacks a newline at the end
36 * of the buffer, but we do want to make sure that we
37 * have a newline there. If the separator isn't already
38 * a newline, add an extra one.
39 * - unlike other log messages, the one-line format does
40 * not have an empty line between entries.
43 if (*sep
!= '\n' && opt
->commit_format
== CMIT_FMT_ONELINE
)
45 if (opt
->shown_one
&& opt
->commit_format
!= CMIT_FMT_ONELINE
)
50 * Print header line of header..
53 if (opt
->commit_format
== CMIT_FMT_EMAIL
)
54 printf("From %s Thu Apr 7 15:13:13 2005\n",
55 sha1_to_hex(commit
->object
.sha1
));
58 opt
->commit_format
== CMIT_FMT_ONELINE
? "" : "commit ",
59 diff_unique_abbrev(commit
->object
.sha1
, abbrev_commit
));
61 show_parents(commit
, abbrev_commit
);
64 diff_unique_abbrev(parent
->object
.sha1
,
66 putchar(opt
->commit_format
== CMIT_FMT_ONELINE
? ' ' : '\n');
70 * And then the pretty-printed message itself
72 len
= pretty_print_commit(opt
->commit_format
, commit
, ~0u, this_header
, sizeof(this_header
), abbrev
);
73 printf("%s%s%s", this_header
, extra
, sep
);
76 int log_tree_diff_flush(struct rev_info
*opt
)
78 diffcore_std(&opt
->diffopt
);
80 if (diff_queue_is_empty()) {
81 int saved_fmt
= opt
->diffopt
.output_format
;
82 opt
->diffopt
.output_format
= DIFF_FORMAT_NO_OUTPUT
;
83 diff_flush(&opt
->diffopt
);
84 opt
->diffopt
.output_format
= saved_fmt
;
88 if (opt
->loginfo
&& !opt
->no_commit_id
)
89 show_log(opt
, opt
->loginfo
, opt
->diffopt
.with_stat
? "---\n" : "\n");
90 diff_flush(&opt
->diffopt
);
94 static int diff_root_tree(struct rev_info
*opt
,
95 const unsigned char *new, const char *base
)
99 struct tree_desc empty
, real
;
101 tree
= read_object_with_reference(new, tree_type
, &real
.size
, NULL
);
103 die("unable to read root tree (%s)", sha1_to_hex(new));
108 retval
= diff_tree(&empty
, &real
, base
, &opt
->diffopt
);
110 log_tree_diff_flush(opt
);
114 static int do_diff_combined(struct rev_info
*opt
, struct commit
*commit
)
116 unsigned const char *sha1
= commit
->object
.sha1
;
118 diff_tree_combined_merge(sha1
, opt
->dense_combined_merges
, opt
);
119 return !opt
->loginfo
;
123 * Show the diff of a commit.
125 * Return true if we printed any log info messages
127 static int log_tree_diff(struct rev_info
*opt
, struct commit
*commit
, struct log_info
*log
)
130 struct commit_list
*parents
;
131 unsigned const char *sha1
= commit
->object
.sha1
;
137 parents
= commit
->parents
;
139 if (opt
->show_root_diff
)
140 diff_root_tree(opt
, sha1
, "");
141 return !opt
->loginfo
;
144 /* More than one parent? */
145 if (parents
&& parents
->next
) {
146 if (opt
->ignore_merges
)
148 else if (opt
->combine_merges
)
149 return do_diff_combined(opt
, commit
);
151 /* If we show individual diffs, show the parent info */
152 log
->parent
= parents
->item
;
157 struct commit
*parent
= parents
->item
;
159 diff_tree_sha1(parent
->object
.sha1
, sha1
, "", &opt
->diffopt
);
160 log_tree_diff_flush(opt
);
162 showed_log
|= !opt
->loginfo
;
164 /* Set up the log info for the next parent, if any.. */
165 parents
= parents
->next
;
168 log
->parent
= parents
->item
;
174 int log_tree_commit(struct rev_info
*opt
, struct commit
*commit
)
183 shown
= log_tree_diff(opt
, commit
, &log
);
184 if (!shown
&& opt
->loginfo
&& opt
->always_show_header
) {
186 show_log(opt
, opt
->loginfo
, "");