1
+
2
#include "cache.h"
3
#include "diff.h"
4
#include "commit.h"
5
#include "log-tree.h"
6
7
+void show_log(struct rev_info *opt, struct log_info *log, const char *sep)
8
+{
9
+ static char this_header[16384];
10
+ struct commit *commit = log->commit, *parent = log->parent;
11
+ int abbrev = opt->diffopt.abbrev;
12
+ int abbrev_commit = opt->abbrev_commit ? opt->abbrev : 40;
13
+ int len;
14
+
15
+ opt->loginfo = NULL;
16
+ if (!opt->verbose_header) {
17
+ puts(sha1_to_hex(commit->object.sha1));
18
+ return;
19
+ }
20
+
21
+ /*
22
+ * Whitespace between commit messages, unless we are oneline
23
+ */
24
+ if (opt->shown_one && opt->commit_format != CMIT_FMT_ONELINE)
25
+ putchar('\n');
26
+ opt->shown_one = 1;
27
+
28
+ /*
29
+ * Print header line of header..
30
+ */
31
+ printf("%s%s",
32
+ opt->commit_format == CMIT_FMT_ONELINE ? "" : "commit ",
33
+ diff_unique_abbrev(commit->object.sha1, abbrev_commit));
34
+ if (parent)
35
+ printf(" (from %s)", diff_unique_abbrev(parent->object.sha1, abbrev_commit));
36
+ putchar(opt->commit_format == CMIT_FMT_ONELINE ? ' ' : '\n');
37
+
38
+ /*
39
+ * And then the pretty-printed message itself
40
+ */
41
+ len = pretty_print_commit(opt->commit_format, commit, ~0u, this_header, sizeof(this_header), abbrev);
42
+ printf("%s%s", this_header, sep);
43
+}
44
+
45
int log_tree_diff_flush(struct rev_info *opt)
46
{
47
diffcore_std(&opt->diffopt);
48
+
49
if (diff_queue_is_empty()) {
50
int saved_fmt = opt->diffopt.output_format;
51
opt->diffopt.output_format = DIFF_FORMAT_NO_OUTPUT;
53
opt->diffopt.output_format = saved_fmt;
54
return 0;
55
}
16
- if (opt->header) {
17
- if (!opt->no_commit_id)
18
- printf("%s%c", opt->header,
19
- opt->diffopt.line_termination);
20
- opt->header = NULL;
21
- }
56
+
57
+ if (opt->loginfo && !opt->no_commit_id)
58
+ show_log(opt, opt->loginfo, "\n");
59
diff_flush(&opt->diffopt);
60
return 1;
61
}
80
return retval;
81
}
82
46
-static const char *get_header(struct rev_info *opt,
47
- const unsigned char *commit_sha1,
48
- const unsigned char *parent_sha1,
49
- const struct commit *commit)
50
-{
51
- static char this_header[16384];
52
- int offset;
53
- unsigned long len;
54
- int abbrev = opt->diffopt.abbrev;
55
- const char *msg = commit->buffer;
56
-
57
- if (opt->use_precomputed_header)
58
- return opt->use_precomputed_header;
59
-
60
- if (!opt->verbose_header)
61
- return sha1_to_hex(commit_sha1);
62
-
63
- len = strlen(msg);
64
-
65
- offset = sprintf(this_header, "%s%s ",
66
- opt->header_prefix,
67
- diff_unique_abbrev(commit_sha1, abbrev));
68
- if (commit_sha1 != parent_sha1)
69
- offset += sprintf(this_header + offset, "(from %s)\n",
70
- parent_sha1
71
- ? diff_unique_abbrev(parent_sha1, abbrev)
72
- : "root");
73
- else
74
- offset += sprintf(this_header + offset, "(from parents)\n");
75
- offset += pretty_print_commit(opt->commit_format, commit, len,
76
- this_header + offset,
77
- sizeof(this_header) - offset, abbrev);
78
- return this_header;
79
-}
80
-
81
-static const char *generate_header(struct rev_info *opt,
82
- const unsigned char *commit_sha1,
83
- const unsigned char *parent_sha1,
84
- const struct commit *commit)
85
-{
86
- const char *header = get_header(opt, commit_sha1, parent_sha1, commit);
87
-
88
- if (opt->always_show_header) {
89
- puts(header);
90
- header = NULL;
91
- }
92
- return header;
93
-}
94
-
83
static int do_diff_combined(struct rev_info *opt, struct commit *commit)
84
{
85
unsigned const char *sha1 = commit->object.sha1;
86
99
- opt->header = generate_header(opt, sha1, sha1, commit);
100
- opt->header = diff_tree_combined_merge(sha1, opt->header,
101
- opt->dense_combined_merges,
102
- &opt->diffopt);
103
- if (!opt->header && opt->verbose_header)
104
- opt->header_prefix = "\ndiff-tree ";
105
- return 0;
87
+ diff_tree_combined_merge(sha1, opt->dense_combined_merges, opt);
88
+ return !opt->loginfo;
89
}
90
108
-int log_tree_commit(struct rev_info *opt, struct commit *commit)
91
+/*
92
+ * Show the diff of a commit.
93
+ *
94
+ * Return true if we printed any log info messages
95
+ */
96
+static int log_tree_diff(struct rev_info *opt, struct commit *commit, struct log_info *log)
97
{
98
+ int showed_log;
99
struct commit_list *parents;
100
unsigned const char *sha1 = commit->object.sha1;
101
102
+ if (!opt->diff)
103
+ return 0;
104
+
105
/* Root commit? */
114
- if (opt->show_root_diff && !commit->parents) {
115
- opt->header = generate_header(opt, sha1, NULL, commit);
116
- diff_root_tree(opt, sha1, "");
106
+ parents = commit->parents;
107
+ if (!parents) {
108
+ if (opt->show_root_diff)
109
+ diff_root_tree(opt, sha1, "");
110
+ return !opt->loginfo;
111
}
112
113
/* More than one parent? */
120
- if (commit->parents && commit->parents->next) {
114
+ if (parents && parents->next) {
115
if (opt->ignore_merges)
116
return 0;
117
else if (opt->combine_merges)
118
return do_diff_combined(opt, commit);
119
+
120
+ /* If we show individual diffs, show the parent info */
121
+ log->parent = parents->item;
122
}
123
127
- for (parents = commit->parents; parents; parents = parents->next) {
124
+ showed_log = 0;
125
+ for (;;) {
126
struct commit *parent = parents->item;
129
- unsigned const char *psha1 = parent->object.sha1;
130
- opt->header = generate_header(opt, sha1, psha1, commit);
131
- diff_tree_sha1(psha1, sha1, "", &opt->diffopt);
132
- log_tree_diff_flush(opt);
127
134
- if (!opt->header && opt->verbose_header)
135
- opt->header_prefix = "\ndiff-tree ";
128
+ diff_tree_sha1(parent->object.sha1, sha1, "", &opt->diffopt);
129
+ log_tree_diff_flush(opt);
130
+
131
+ showed_log |= !opt->loginfo;
132
+
133
+ /* Set up the log info for the next parent, if any.. */
134
+ parents = parents->next;
135
+ if (!parents)
136
+ break;
137
+ log->parent = parents->item;
138
+ opt->loginfo = log;
139
+ }
140
+ return showed_log;
141
+}
142
+
143
+int log_tree_commit(struct rev_info *opt, struct commit *commit)
144
+{
145
+ struct log_info log;
146
+
147
+ log.commit = commit;
148
+ log.parent = NULL;
149
+ opt->loginfo = &log;
150
+
151
+ if (!log_tree_diff(opt, commit, &log) && opt->loginfo && opt->always_show_header) {
152
+ log.parent = NULL;
153
+ show_log(opt, opt->loginfo, "");
154
}
155
+ opt->loginfo = NULL;
156
return 0;
157
}