Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 813 lines (727 sloc) 22.88 kb
5f1c3f0 log-tree: separate major part of diff-tree.
Junio C Hamano authored
1 #include "cache.h"
2 #include "diff.h"
3 #include "commit.h"
cab4feb move load_ref_decorations() to log-tree.c and export it
René Scharfe authored
4 #include "tag.h"
7fefda5 Adam Simpkins log and rev-list: add --graph option
simpkins authored
5 #include "graph.h"
5f1c3f0 log-tree: separate major part of diff-tree.
Junio C Hamano authored
6 #include "log-tree.h"
8860fd4 dscho Teach the revision walker to walk by reflogs with --walk-reflogs
dscho authored
7 #include "reflog-walk.h"
cab4feb move load_ref_decorations() to log-tree.c and export it
René Scharfe authored
8 #include "refs.h"
b079c50 trast format-patch: track several references
trast authored
9 #include "string-list.h"
67a4b58 nazri log --decorate: Colorize commit decorations
nazri authored
10 #include "color.h"
0c37f1f Junio C Hamano log: --show-signature
authored
11 #include "gpg-interface.h"
959a262 Brandon Casey Unify appending signoff in format-patch, commit and sequencer
drafnel authored
12 #include "sequencer.h"
12da1d1 trast Implement line-history search (git log -L)
trast authored
13 #include "line-log.h"
5f1c3f0 log-tree: separate major part of diff-tree.
Junio C Hamano authored
14
2608c24 Jeff King log-tree: make name_decoration hash static
peff authored
15 static struct decoration name_decoration = { "object names" };
a752412 nazri log-tree.c: Use struct name_decoration's type for classifying decoration
nazri authored
16
67a4b58 nazri log --decorate: Colorize commit decorations
nazri authored
17 static char decoration_colors[][COLOR_MAXLEN] = {
18 GIT_COLOR_RESET,
19 GIT_COLOR_BOLD_GREEN, /* REF_LOCAL */
20 GIT_COLOR_BOLD_RED, /* REF_REMOTE */
21 GIT_COLOR_BOLD_YELLOW, /* REF_TAG */
22 GIT_COLOR_BOLD_MAGENTA, /* REF_STASH */
23 GIT_COLOR_BOLD_CYAN, /* REF_HEAD */
76f5df3 Nguyễn Thái Ngọc Duy log: decorate grafted commits with "grafted"
pclouds authored
24 GIT_COLOR_BOLD_BLUE, /* GRAFTED */
67a4b58 nazri log --decorate: Colorize commit decorations
nazri authored
25 };
26
27 static const char *decorate_get_color(int decorate_use_color, enum decoration_type ix)
28 {
daa0c3d Jeff King color: delay auto-color decision until point of use
peff authored
29 if (want_color(decorate_use_color))
67a4b58 nazri log --decorate: Colorize commit decorations
nazri authored
30 return decoration_colors[ix];
31 return "";
32 }
33
5e11bee nazri Allow customizable commit decorations colors
nazri authored
34 static int parse_decorate_color_slot(const char *slot)
35 {
36 /*
37 * We're comparing with 'ignore-case' on
38 * (because config.c sets them all tolower),
39 * but let's match the letters in the literal
40 * string values here with how they are
41 * documented in Documentation/config.txt, for
42 * consistency.
43 *
44 * We love being consistent, don't we?
45 */
46 if (!strcasecmp(slot, "branch"))
47 return DECORATION_REF_LOCAL;
48 if (!strcasecmp(slot, "remoteBranch"))
49 return DECORATION_REF_REMOTE;
50 if (!strcasecmp(slot, "tag"))
51 return DECORATION_REF_TAG;
52 if (!strcasecmp(slot, "stash"))
53 return DECORATION_REF_STASH;
54 if (!strcasecmp(slot, "HEAD"))
55 return DECORATION_REF_HEAD;
56 return -1;
57 }
58
8852117 jrn pass config slots as pointers instead of offsets
jrn authored
59 int parse_decorate_color_config(const char *var, const char *slot_name, const char *value)
5e11bee nazri Allow customizable commit decorations colors
nazri authored
60 {
8852117 jrn pass config slots as pointers instead of offsets
jrn authored
61 int slot = parse_decorate_color_slot(slot_name);
5e11bee nazri Allow customizable commit decorations colors
nazri authored
62 if (slot < 0)
63 return 0;
64 if (!value)
65 return config_error_nonbool(var);
f6c5a29 Jeff King color_parse: do not mention variable name in error message
peff authored
66 return color_parse(value, decoration_colors[slot]);
5e11bee nazri Allow customizable commit decorations colors
nazri authored
67 }
68
67a4b58 nazri log --decorate: Colorize commit decorations
nazri authored
69 /*
70 * log-tree.c uses DIFF_OPT_TST for determining whether to use color
71 * for showing the commit sha1, use the same check for --decorate
72 */
73 #define decorate_get_color_opt(o, ix) \
f1c9626 Jeff King diff: refactor COLOR_DIFF from a flag into an int
peff authored
74 decorate_get_color((o)->use_color, ix)
67a4b58 nazri log --decorate: Colorize commit decorations
nazri authored
75
662174d Jeff King log-tree: make add_name_decoration a public function
peff authored
76 void add_name_decoration(enum decoration_type type, const char *name, struct object *obj)
cab4feb move load_ref_decorations() to log-tree.c and export it
René Scharfe authored
77 {
78 int nlen = strlen(name);
2e3dfb2 Jeff King log-tree: use FLEX_ARRAY in name_decoration
peff authored
79 struct name_decoration *res = xmalloc(sizeof(*res) + nlen + 1);
a752412 nazri log-tree.c: Use struct name_decoration's type for classifying decoration
nazri authored
80 memcpy(res->name, name, nlen + 1);
81 res->type = type;
cab4feb move load_ref_decorations() to log-tree.c and export it
René Scharfe authored
82 res->next = add_decoration(&name_decoration, obj, res);
83 }
84
2608c24 Jeff King log-tree: make name_decoration hash static
peff authored
85 const struct name_decoration *get_name_decoration(const struct object *obj)
86 {
87 return lookup_decoration(&name_decoration, obj);
88 }
89
cab4feb move load_ref_decorations() to log-tree.c and export it
René Scharfe authored
90 static int add_ref_decoration(const char *refname, const unsigned char *sha1, int flags, void *cb_data)
91 {
5267d29 Nguyễn Thái Ngọc Duy log: decorate "replaced" on to replaced commits
pclouds authored
92 struct object *obj;
a752412 nazri log-tree.c: Use struct name_decoration's type for classifying decoration
nazri authored
93 enum decoration_type type = DECORATION_NONE;
5267d29 Nguyễn Thái Ngọc Duy log: decorate "replaced" on to replaced commits
pclouds authored
94
5955654 Christian Couder replace {pre,suf}fixcmp() with {starts,ends}_with()
chriscool authored
95 if (starts_with(refname, "refs/replace/")) {
5267d29 Nguyễn Thái Ngọc Duy log: decorate "replaced" on to replaced commits
pclouds authored
96 unsigned char original_sha1[20];
afc711b Michael Haggerty rename read_replace_refs to check_replace_refs
mhagger authored
97 if (!check_replace_refs)
b9ad500 Michael J Gruber log: Do not decorate replacements with --no-replace-objects
mjg authored
98 return 0;
5267d29 Nguyễn Thái Ngọc Duy log: decorate "replaced" on to replaced commits
pclouds authored
99 if (get_sha1_hex(refname + 13, original_sha1)) {
100 warning("invalid replace ref %s", refname);
101 return 0;
102 }
103 obj = parse_object(original_sha1);
104 if (obj)
105 add_name_decoration(DECORATION_GRAFTED, "replaced", obj);
106 return 0;
107 }
108
109 obj = parse_object(sha1);
cab4feb move load_ref_decorations() to log-tree.c and export it
René Scharfe authored
110 if (!obj)
111 return 0;
a752412 nazri log-tree.c: Use struct name_decoration's type for classifying decoration
nazri authored
112
5955654 Christian Couder replace {pre,suf}fixcmp() with {starts,ends}_with()
chriscool authored
113 if (starts_with(refname, "refs/heads/"))
a752412 nazri log-tree.c: Use struct name_decoration's type for classifying decoration
nazri authored
114 type = DECORATION_REF_LOCAL;
5955654 Christian Couder replace {pre,suf}fixcmp() with {starts,ends}_with()
chriscool authored
115 else if (starts_with(refname, "refs/remotes/"))
a752412 nazri log-tree.c: Use struct name_decoration's type for classifying decoration
nazri authored
116 type = DECORATION_REF_REMOTE;
5955654 Christian Couder replace {pre,suf}fixcmp() with {starts,ends}_with()
chriscool authored
117 else if (starts_with(refname, "refs/tags/"))
a752412 nazri log-tree.c: Use struct name_decoration's type for classifying decoration
nazri authored
118 type = DECORATION_REF_TAG;
97ba642 Nguyễn Thái Ngọc Duy Fix incorrect ref namespace check
pclouds authored
119 else if (!strcmp(refname, "refs/stash"))
a752412 nazri log-tree.c: Use struct name_decoration's type for classifying decoration
nazri authored
120 type = DECORATION_REF_STASH;
97ba642 Nguyễn Thái Ngọc Duy Fix incorrect ref namespace check
pclouds authored
121 else if (!strcmp(refname, "HEAD"))
a752412 nazri log-tree.c: Use struct name_decoration's type for classifying decoration
nazri authored
122 type = DECORATION_REF_HEAD;
123
33e7018 git-log: allow --decorate[=short|full]
Lars Hjemli authored
124 if (!cb_data || *(int *)cb_data == DECORATE_SHORT_REFS)
125 refname = prettify_refname(refname);
a752412 nazri log-tree.c: Use struct name_decoration's type for classifying decoration
nazri authored
126 add_name_decoration(type, refname, obj);
cab4feb move load_ref_decorations() to log-tree.c and export it
René Scharfe authored
127 while (obj->type == OBJ_TAG) {
128 obj = ((struct tag *)obj)->tagged;
129 if (!obj)
130 break;
5e1361c brian m. carlson log: properly handle decorations with chained tags
bk2204 authored
131 if (!obj->parsed)
132 parse_object(obj->sha1);
a752412 nazri log-tree.c: Use struct name_decoration's type for classifying decoration
nazri authored
133 add_name_decoration(DECORATION_REF_TAG, refname, obj);
cab4feb move load_ref_decorations() to log-tree.c and export it
René Scharfe authored
134 }
135 return 0;
136 }
137
76f5df3 Nguyễn Thái Ngọc Duy log: decorate grafted commits with "grafted"
pclouds authored
138 static int add_graft_decoration(const struct commit_graft *graft, void *cb_data)
139 {
140 struct commit *commit = lookup_commit(graft->sha1);
141 if (!commit)
142 return 0;
143 add_name_decoration(DECORATION_GRAFTED, "grafted", &commit->object);
144 return 0;
145 }
146
33e7018 git-log: allow --decorate[=short|full]
Lars Hjemli authored
147 void load_ref_decorations(int flags)
cab4feb move load_ref_decorations() to log-tree.c and export it
René Scharfe authored
148 {
149 static int loaded;
150 if (!loaded) {
151 loaded = 1;
33e7018 git-log: allow --decorate[=short|full]
Lars Hjemli authored
152 for_each_ref(add_ref_decoration, &flags);
77abcbd trast Let --decorate show HEAD position
trast authored
153 head_ref(add_ref_decoration, &flags);
76f5df3 Nguyễn Thái Ngọc Duy log: decorate grafted commits with "grafted"
pclouds authored
154 for_each_commit_graft(add_graft_decoration, NULL);
cab4feb move load_ref_decorations() to log-tree.c and export it
René Scharfe authored
155 }
156 }
157
c8c893c Fix "git-log --parents" breakage post v1.3.0
Linus Torvalds authored
158 static void show_parents(struct commit *commit, int abbrev)
159 {
160 struct commit_list *p;
161 for (p = commit->parents; p ; p = p->next) {
162 struct commit *parent = p->item;
7fcda92 trast log: do not print ellipses with --abbrev-commit
trast authored
163 printf(" %s", find_unique_abbrev(parent->object.sha1, abbrev));
c8c893c Fix "git-log --parents" breakage post v1.3.0
Linus Torvalds authored
164 }
165 }
166
91b849b Jay Soffian log --children
jaysoffian authored
167 static void show_children(struct rev_info *opt, struct commit *commit, int abbrev)
168 {
169 struct commit_list *p = lookup_decoration(&opt->children, &commit->object);
170 for ( ; p; p = p->next) {
171 printf(" %s", find_unique_abbrev(p->item->object.sha1, abbrev));
172 }
173 }
174
9d3f002 Nguyễn Thái Ngọc Duy pretty: share code between format_decoration and show_decorations
pclouds authored
175 /*
9271095 Harry Jeffery pretty: add %D format specifier
eXeC64 authored
176 * The caller makes sure there is no funny color before calling.
177 * format_decorations_extended makes sure the same after return.
9d3f002 Nguyễn Thái Ngọc Duy pretty: share code between format_decoration and show_decorations
pclouds authored
178 */
9271095 Harry Jeffery pretty: add %D format specifier
eXeC64 authored
179 void format_decorations_extended(struct strbuf *sb,
9d3f002 Nguyễn Thái Ngọc Duy pretty: share code between format_decoration and show_decorations
pclouds authored
180 const struct commit *commit,
9271095 Harry Jeffery pretty: add %D format specifier
eXeC64 authored
181 int use_color,
182 const char *prefix,
183 const char *separator,
184 const char *suffix)
ca135e7 Linus Torvalds Add support for "commit name decorations" to log family of commands
torvalds authored
185 {
2608c24 Jeff King log-tree: make name_decoration hash static
peff authored
186 const struct name_decoration *decoration;
67a4b58 nazri log --decorate: Colorize commit decorations
nazri authored
187 const char *color_commit =
9d3f002 Nguyễn Thái Ngọc Duy pretty: share code between format_decoration and show_decorations
pclouds authored
188 diff_get_color(use_color, DIFF_COMMIT);
67a4b58 nazri log --decorate: Colorize commit decorations
nazri authored
189 const char *color_reset =
9d3f002 Nguyễn Thái Ngọc Duy pretty: share code between format_decoration and show_decorations
pclouds authored
190 decorate_get_color(use_color, DECORATION_NONE);
ca135e7 Linus Torvalds Add support for "commit name decorations" to log family of commands
torvalds authored
191
2608c24 Jeff King log-tree: make name_decoration hash static
peff authored
192 decoration = get_name_decoration(&commit->object);
ca135e7 Linus Torvalds Add support for "commit name decorations" to log family of commands
torvalds authored
193 if (!decoration)
194 return;
195 while (decoration) {
9d3f002 Nguyễn Thái Ngọc Duy pretty: share code between format_decoration and show_decorations
pclouds authored
196 strbuf_addstr(sb, color_commit);
197 strbuf_addstr(sb, prefix);
198 strbuf_addstr(sb, decorate_get_color(use_color, decoration->type));
a752412 nazri log-tree.c: Use struct name_decoration's type for classifying decoration
nazri authored
199 if (decoration->type == DECORATION_REF_TAG)
9d3f002 Nguyễn Thái Ngọc Duy pretty: share code between format_decoration and show_decorations
pclouds authored
200 strbuf_addstr(sb, "tag: ");
201 strbuf_addstr(sb, decoration->name);
202 strbuf_addstr(sb, color_reset);
9271095 Harry Jeffery pretty: add %D format specifier
eXeC64 authored
203 prefix = separator;
ca135e7 Linus Torvalds Add support for "commit name decorations" to log family of commands
torvalds authored
204 decoration = decoration->next;
205 }
9d3f002 Nguyễn Thái Ngọc Duy pretty: share code between format_decoration and show_decorations
pclouds authored
206 strbuf_addstr(sb, color_commit);
9271095 Harry Jeffery pretty: add %D format specifier
eXeC64 authored
207 strbuf_addstr(sb, suffix);
9d3f002 Nguyễn Thái Ngọc Duy pretty: share code between format_decoration and show_decorations
pclouds authored
208 strbuf_addstr(sb, color_reset);
209 }
210
211 void show_decorations(struct rev_info *opt, struct commit *commit)
212 {
213 struct strbuf sb = STRBUF_INIT;
214
215 if (opt->show_source && commit->util)
216 printf("\t%s", (char *) commit->util);
217 if (!opt->show_decorations)
218 return;
219 format_decorations(&sb, commit, opt->diffopt.use_color);
220 fputs(sb.buf, stdout);
221 strbuf_release(&sb);
ca135e7 Linus Torvalds Add support for "commit name decorations" to log family of commands
torvalds authored
222 }
223
e00de24 dscho format-patch -n: make sorting easier by padding number
dscho authored
224 static unsigned int digits_in_number(unsigned int number)
225 {
226 unsigned int i = 10, result = 1;
227 while (i <= number) {
228 i *= 10;
229 result++;
230 }
231 return result;
232 }
233
d28b5d4 Junio C Hamano get_patch_filename(): split into two functions
authored
234 void fmt_output_subject(struct strbuf *filename,
235 const char *subject,
021f2f4 Junio C Hamano get_patch_filename(): simplify function signature
authored
236 struct rev_info *info)
6fa8e62 Stephen Boyd format-patch: move get_patch_filename() into log-tree
bebarino authored
237 {
021f2f4 Junio C Hamano get_patch_filename(): simplify function signature
authored
238 const char *suffix = info->patch_suffix;
239 int nr = info->nr;
d28b5d4 Junio C Hamano get_patch_filename(): split into two functions
authored
240 int start_len = filename->len;
241 int max_len = start_len + FORMAT_PATCH_NAME_MAX - (strlen(suffix) + 1);
242
5fe10fe Junio C Hamano format-patch: add --reroll-count=$N option
authored
243 if (0 < info->reroll_count)
244 strbuf_addf(filename, "v%d-", info->reroll_count);
d28b5d4 Junio C Hamano get_patch_filename(): split into two functions
authored
245 strbuf_addf(filename, "%04d-%s", nr, subject);
246
247 if (max_len < filename->len)
248 strbuf_setlen(filename, max_len);
249 strbuf_addstr(filename, suffix);
250 }
251
252 void fmt_output_commit(struct strbuf *filename,
253 struct commit *commit,
254 struct rev_info *info)
255 {
256 struct pretty_print_context ctx = {0};
257 struct strbuf subject = STRBUF_INIT;
258
259 format_commit_message(commit, "%f", &subject, &ctx);
260 fmt_output_subject(filename, subject.buf, info);
261 strbuf_release(&subject);
6fa8e62 Stephen Boyd format-patch: move get_patch_filename() into log-tree
bebarino authored
262 }
263
108dab2 Stephen Boyd format-patch: --attach/inline uses filename instead of SHA1
bebarino authored
264 void log_write_email_headers(struct rev_info *opt, struct commit *commit,
267123b Junio C Hamano Merge branch 'maint'
authored
265 const char **subject_p,
266 const char **extra_headers_p,
267 int *need_8bit_cte_p)
b02bd65 Export some email and pretty-printing functions
Daniel Barkalow authored
268 {
269 const char *subject = NULL;
270 const char *extra_headers = opt->extra_headers;
108dab2 Stephen Boyd format-patch: --attach/inline uses filename instead of SHA1
bebarino authored
271 const char *name = sha1_to_hex(commit->object.sha1);
267123b Junio C Hamano Merge branch 'maint'
authored
272
273 *need_8bit_cte_p = 0; /* unknown */
b02bd65 Export some email and pretty-printing functions
Daniel Barkalow authored
274 if (opt->total > 0) {
275 static char buffer[64];
276 snprintf(buffer, sizeof(buffer),
e7af8e4 Jeff King format-patch: make zero-length subject prefixes prettier
peff authored
277 "Subject: [%s%s%0*d/%d] ",
b02bd65 Export some email and pretty-printing functions
Daniel Barkalow authored
278 opt->subject_prefix,
e7af8e4 Jeff King format-patch: make zero-length subject prefixes prettier
peff authored
279 *opt->subject_prefix ? " " : "",
b02bd65 Export some email and pretty-printing functions
Daniel Barkalow authored
280 digits_in_number(opt->total),
281 opt->nr, opt->total);
282 subject = buffer;
283 } else if (opt->total == 0 && opt->subject_prefix && *opt->subject_prefix) {
284 static char buffer[256];
285 snprintf(buffer, sizeof(buffer),
286 "Subject: [%s] ",
287 opt->subject_prefix);
288 subject = buffer;
289 } else {
290 subject = "Subject: ";
291 }
292
293 printf("From %s Mon Sep 17 00:00:00 2001\n", name);
7fefda5 Adam Simpkins log and rev-list: add --graph option
simpkins authored
294 graph_show_oneline(opt->graph);
295 if (opt->message_id) {
b02bd65 Export some email and pretty-printing functions
Daniel Barkalow authored
296 printf("Message-Id: <%s>\n", opt->message_id);
7fefda5 Adam Simpkins log and rev-list: add --graph option
simpkins authored
297 graph_show_oneline(opt->graph);
298 }
b079c50 trast format-patch: track several references
trast authored
299 if (opt->ref_message_ids && opt->ref_message_ids->nr > 0) {
300 int i, n;
301 n = opt->ref_message_ids->nr;
302 printf("In-Reply-To: <%s>\n", opt->ref_message_ids->items[n-1].string);
303 for (i = 0; i < n; i++)
304 printf("%s<%s>\n", (i > 0 ? "\t" : "References: "),
305 opt->ref_message_ids->items[i].string);
7fefda5 Adam Simpkins log and rev-list: add --graph option
simpkins authored
306 graph_show_oneline(opt->graph);
307 }
b02bd65 Export some email and pretty-printing functions
Daniel Barkalow authored
308 if (opt->mime_boundary) {
309 static char subject_buffer[1024];
310 static char buffer[1024];
108dab2 Stephen Boyd format-patch: --attach/inline uses filename instead of SHA1
bebarino authored
311 struct strbuf filename = STRBUF_INIT;
267123b Junio C Hamano Merge branch 'maint'
authored
312 *need_8bit_cte_p = -1; /* NEVER */
b02bd65 Export some email and pretty-printing functions
Daniel Barkalow authored
313 snprintf(subject_buffer, sizeof(subject_buffer) - 1,
314 "%s"
315 "MIME-Version: 1.0\n"
316 "Content-Type: multipart/mixed;"
317 " boundary=\"%s%s\"\n"
318 "\n"
319 "This is a multi-part message in MIME "
320 "format.\n"
321 "--%s%s\n"
322 "Content-Type: text/plain; "
323 "charset=UTF-8; format=fixed\n"
324 "Content-Transfer-Encoding: 8bit\n\n",
325 extra_headers ? extra_headers : "",
326 mime_boundary_leader, opt->mime_boundary,
327 mime_boundary_leader, opt->mime_boundary);
328 extra_headers = subject_buffer;
329
38ec23a Junio C Hamano get_patch_filename(): drop "just-numbers" hack
authored
330 if (opt->numbered_files)
331 strbuf_addf(&filename, "%d", opt->nr);
332 else
d28b5d4 Junio C Hamano get_patch_filename(): split into two functions
authored
333 fmt_output_commit(&filename, commit, opt);
b02bd65 Export some email and pretty-printing functions
Daniel Barkalow authored
334 snprintf(buffer, sizeof(buffer) - 1,
6b2fbaa Kevin Ballard format-patch: Produce better output with --inline or --attach
kballard authored
335 "\n--%s%s\n"
b02bd65 Export some email and pretty-printing functions
Daniel Barkalow authored
336 "Content-Type: text/x-patch;"
108dab2 Stephen Boyd format-patch: --attach/inline uses filename instead of SHA1
bebarino authored
337 " name=\"%s\"\n"
b02bd65 Export some email and pretty-printing functions
Daniel Barkalow authored
338 "Content-Transfer-Encoding: 8bit\n"
339 "Content-Disposition: %s;"
108dab2 Stephen Boyd format-patch: --attach/inline uses filename instead of SHA1
bebarino authored
340 " filename=\"%s\"\n\n",
b02bd65 Export some email and pretty-printing functions
Daniel Barkalow authored
341 mime_boundary_leader, opt->mime_boundary,
108dab2 Stephen Boyd format-patch: --attach/inline uses filename instead of SHA1
bebarino authored
342 filename.buf,
b02bd65 Export some email and pretty-printing functions
Daniel Barkalow authored
343 opt->no_inline ? "attachment" : "inline",
108dab2 Stephen Boyd format-patch: --attach/inline uses filename instead of SHA1
bebarino authored
344 filename.buf);
b02bd65 Export some email and pretty-printing functions
Daniel Barkalow authored
345 opt->diffopt.stat_sep = buffer;
108dab2 Stephen Boyd format-patch: --attach/inline uses filename instead of SHA1
bebarino authored
346 strbuf_release(&filename);
b02bd65 Export some email and pretty-printing functions
Daniel Barkalow authored
347 }
348 *subject_p = subject;
349 *extra_headers_p = extra_headers;
350 }
351
c6b3ec4 Junio C Hamano log-tree.c: small refactor in show_signature()
authored
352 static void show_sig_lines(struct rev_info *opt, int status, const char *bol)
353 {
354 const char *color, *reset, *eol;
355
356 color = diff_get_color_opt(&opt->diffopt,
357 status ? DIFF_WHITESPACE : DIFF_FRAGINFO);
358 reset = diff_get_color_opt(&opt->diffopt, DIFF_RESET);
359 while (*bol) {
360 eol = strchrnul(bol, '\n');
361 printf("%s%.*s%s%s", color, (int)(eol - bol), bol, reset,
362 *eol ? "\n" : "");
cf3983d Zoltan Klinger log: fix indentation for --graph --show-signature
zklinger authored
363 graph_show_oneline(opt->graph);
c6b3ec4 Junio C Hamano log-tree.c: small refactor in show_signature()
authored
364 bol = (*eol) ? (eol + 1) : eol;
365 }
366 }
367
0c37f1f Junio C Hamano log: --show-signature
authored
368 static void show_signature(struct rev_info *opt, struct commit *commit)
369 {
370 struct strbuf payload = STRBUF_INIT;
371 struct strbuf signature = STRBUF_INIT;
372 struct strbuf gpg_output = STRBUF_INIT;
373 int status;
374
218aa3a Jeff King reuse cached commit buffer when parsing signatures
peff authored
375 if (parse_signed_commit(commit, &payload, &signature) <= 0)
0c37f1f Junio C Hamano log: --show-signature
authored
376 goto out;
377
378 status = verify_signed_buffer(payload.buf, payload.len,
379 signature.buf, signature.len,
9cc4ac8 Michael J Gruber gpg_interface: allow to request status return
mjg authored
380 &gpg_output, NULL);
0c37f1f Junio C Hamano log: --show-signature
authored
381 if (status && !gpg_output.len)
382 strbuf_addstr(&gpg_output, "No signature\n");
383
c6b3ec4 Junio C Hamano log-tree.c: small refactor in show_signature()
authored
384 show_sig_lines(opt, status, gpg_output.buf);
0c37f1f Junio C Hamano log: --show-signature
authored
385
386 out:
387 strbuf_release(&gpg_output);
388 strbuf_release(&payload);
389 strbuf_release(&signature);
390 }
391
824958e Junio C Hamano log-tree: show mergetag in log --show-signature output
authored
392 static int which_parent(const unsigned char *sha1, const struct commit *commit)
393 {
394 int nth;
395 const struct commit_list *parent;
396
397 for (nth = 0, parent = commit->parents; parent; parent = parent->next) {
398 if (!hashcmp(parent->item->object.sha1, sha1))
399 return nth;
400 nth++;
401 }
402 return -1;
403 }
404
d041ffa Junio C Hamano log --show-signature: reword the common two-head merge case
authored
405 static int is_common_merge(const struct commit *commit)
406 {
407 return (commit->parents
408 && commit->parents->next
409 && !commit->parents->next->next);
410 }
411
063da62 Christian Couder commit: add for_each_mergetag()
chriscool authored
412 static void show_one_mergetag(struct commit *commit,
824958e Junio C Hamano log-tree: show mergetag in log --show-signature output
authored
413 struct commit_extra_header *extra,
063da62 Christian Couder commit: add for_each_mergetag()
chriscool authored
414 void *data)
824958e Junio C Hamano log-tree: show mergetag in log --show-signature output
authored
415 {
063da62 Christian Couder commit: add for_each_mergetag()
chriscool authored
416 struct rev_info *opt = (struct rev_info *)data;
824958e Junio C Hamano log-tree: show mergetag in log --show-signature output
authored
417 unsigned char sha1[20];
418 struct tag *tag;
419 struct strbuf verify_message;
420 int status, nth;
421 size_t payload_size, gpg_message_offset;
422
423 hash_sha1_file(extra->value, extra->len, typename(OBJ_TAG), sha1);
424 tag = lookup_tag(sha1);
425 if (!tag)
426 return; /* error message already given */
427
428 strbuf_init(&verify_message, 256);
429 if (parse_tag_buffer(tag, extra->value, extra->len))
430 strbuf_addstr(&verify_message, "malformed mergetag\n");
d041ffa Junio C Hamano log --show-signature: reword the common two-head merge case
authored
431 else if (is_common_merge(commit) &&
432 !hashcmp(tag->tagged->sha1,
433 commit->parents->next->item->object.sha1))
434 strbuf_addf(&verify_message,
435 "merged tag '%s'\n", tag->tag);
824958e Junio C Hamano log-tree: show mergetag in log --show-signature output
authored
436 else if ((nth = which_parent(tag->tagged->sha1, commit)) < 0)
437 strbuf_addf(&verify_message, "tag %s names a non-parent %s\n",
438 tag->tag, tag->tagged->sha1);
439 else
440 strbuf_addf(&verify_message,
441 "parent #%d, tagged '%s'\n", nth + 1, tag->tag);
442 gpg_message_offset = verify_message.len;
443
444 payload_size = parse_signature(extra->value, extra->len);
1315093 Michael J Gruber log-tree: rely upon the check in the gpg_interface
mjg authored
445 status = -1;
42c55ce Michael J Gruber log: correctly identify mergetag signature verification status
mjg authored
446 if (extra->len > payload_size) {
447 /* could have a good signature */
448 if (!verify_signed_buffer(extra->value, payload_size,
449 extra->value + payload_size,
450 extra->len - payload_size,
451 &verify_message, NULL))
452 status = 0; /* good */
453 else if (verify_message.len <= gpg_message_offset)
454 strbuf_addstr(&verify_message, "No signature\n");
455 /* otherwise we couldn't verify, which is shown as bad */
456 }
824958e Junio C Hamano log-tree: show mergetag in log --show-signature output
authored
457
458 show_sig_lines(opt, status, verify_message.buf);
459 strbuf_release(&verify_message);
460 }
461
462 static void show_mergetag(struct rev_info *opt, struct commit *commit)
463 {
063da62 Christian Couder commit: add for_each_mergetag()
chriscool authored
464 for_each_mergetag(show_one_mergetag, commit, opt);
824958e Junio C Hamano log-tree: show mergetag in log --show-signature output
authored
465 }
466
0286565 Adam Simpkins Remove dead code: show_log() sep argument and diff_options.msg_sep
simpkins authored
467 void show_log(struct rev_info *opt)
9153983 Log message printout cleanups
Linus Torvalds authored
468 {
f285a2d Replace calls to strbuf_init(&foo, 0) with STRBUF_INIT initializer
Brandon Casey authored
469 struct strbuf msgbuf = STRBUF_INIT;
39bc9a6 tihirvon Add msg_sep to diff_options
tihirvon authored
470 struct log_info *log = opt->loginfo;
9153983 Log message printout cleanups
Linus Torvalds authored
471 struct commit *commit = log->commit, *parent = log->parent;
472 int abbrev_commit = opt->abbrev_commit ? opt->abbrev : 40;
dd2e794 trast Refactor pretty_print_commit arguments into a struct
trast authored
473 const char *extra_headers = opt->extra_headers;
474 struct pretty_print_context ctx = {0};
9153983 Log message printout cleanups
Linus Torvalds authored
475
476 opt->loginfo = NULL;
477 if (!opt->verbose_header) {
7fefda5 Adam Simpkins log and rev-list: add --graph option
simpkins authored
478 graph_show_commit(opt->graph);
479
1df2d65 Michael J Gruber rev-list/log: factor out revision mark generation
mjg authored
480 if (!opt->graph)
b1b4755 Michael J Gruber git-log: put space after commit mark
mjg authored
481 put_revision_mark(opt, commit);
7fcda92 trast log: do not print ellipses with --abbrev-commit
trast authored
482 fputs(find_unique_abbrev(commit->object.sha1, abbrev_commit), stdout);
885cf80 Adam Simpkins revision API: split parent rewriting and parent printing options
simpkins authored
483 if (opt->print_parents)
c8c893c Fix "git-log --parents" breakage post v1.3.0
Linus Torvalds authored
484 show_parents(commit, abbrev_commit);
91b849b Jay Soffian log --children
jaysoffian authored
485 if (opt->children.name)
486 show_children(opt, commit, abbrev_commit);
0f3a290 Linus Torvalds Add a 'source' decorator for commits
torvalds authored
487 show_decorations(opt, commit);
7fefda5 Adam Simpkins log and rev-list: add --graph option
simpkins authored
488 if (opt->graph && !graph_is_commit_finished(opt->graph)) {
489 putchar('\n');
490 graph_show_remainder(opt->graph);
491 }
1dcb692 pugmajere log-tree: show_log() should respect the setting of diffopt->line_termina...
pugmajere authored
492 putchar(opt->diffopt.line_termination);
9153983 Log message printout cleanups
Linus Torvalds authored
493 return;
494 }
495
496 /*
8715227 Jeff King log-tree: fix confusing comment
peff authored
497 * If use_terminator is set, we already handled any record termination
498 * at the end of the last record.
0286565 Adam Simpkins Remove dead code: show_log() sep argument and diff_options.msg_sep
simpkins authored
499 * Otherwise, add a diffopt.line_termination character before all
500 * entries but the first. (IOW, as a separator between entries)
9153983 Log message printout cleanups
Linus Torvalds authored
501 */
7fefda5 Adam Simpkins log and rev-list: add --graph option
simpkins authored
502 if (opt->shown_one && !opt->use_terminator) {
503 /*
504 * If entries are separated by a newline, the output
505 * should look human-readable. If the last entry ended
506 * with a newline, print the graph output before this
507 * newline. Otherwise it will end up as a completely blank
508 * line and will look like a gap in the graph.
509 *
510 * If the entry separator is not a newline, the output is
511 * primarily intended for programmatic consumption, and we
512 * never want the extra graph output before the entry
513 * separator.
514 */
515 if (opt->diffopt.line_termination == '\n' &&
516 !opt->missing_newline)
517 graph_show_padding(opt->graph);
abd4e22 Linus Torvalds Fix "git log -z" behaviour
torvalds authored
518 putchar(opt->diffopt.line_termination);
7fefda5 Adam Simpkins log and rev-list: add --graph option
simpkins authored
519 }
9153983 Log message printout cleanups
Linus Torvalds authored
520 opt->shown_one = 1;
521
522 /*
7fefda5 Adam Simpkins log and rev-list: add --graph option
simpkins authored
523 * If the history graph was requested,
524 * print the graph, up to this commit's line
525 */
526 graph_show_commit(opt->graph);
527
528 /*
9153983 Log message printout cleanups
Linus Torvalds authored
529 * Print header line of header..
530 */
3eefc18 Tentative built-in format-patch.
Junio C Hamano authored
531
596524b dscho Teach fmt-patch about --numbered
dscho authored
532 if (opt->commit_format == CMIT_FMT_EMAIL) {
dd2e794 trast Refactor pretty_print_commit arguments into a struct
trast authored
533 log_write_email_headers(opt, commit, &ctx.subject, &extra_headers,
534 &ctx.need_8bit_cte);
e52a5de dscho pretty-formats: add 'format:<string>'
dscho authored
535 } else if (opt->commit_format != CMIT_FMT_USERFORMAT) {
8f67f8a Pierre Habouzit Make the diff_options bitfields be an unsigned with explicit masks.
MadCoder authored
536 fputs(diff_get_color_opt(&opt->diffopt, DIFF_COMMIT), stdout);
74bd902 Teach all of log family --left-right output.
Junio C Hamano authored
537 if (opt->commit_format != CMIT_FMT_ONELINE)
538 fputs("commit ", stdout);
7528f27 Adam Simpkins log --graph --left-right: show left/right information in place of '*'
simpkins authored
539
1df2d65 Michael J Gruber rev-list/log: factor out revision mark generation
mjg authored
540 if (!opt->graph)
b1b4755 Michael J Gruber git-log: put space after commit mark
mjg authored
541 put_revision_mark(opt, commit);
7fcda92 trast log: do not print ellipses with --abbrev-commit
trast authored
542 fputs(find_unique_abbrev(commit->object.sha1, abbrev_commit),
74bd902 Teach all of log family --left-right output.
Junio C Hamano authored
543 stdout);
885cf80 Adam Simpkins revision API: split parent rewriting and parent printing options
simpkins authored
544 if (opt->print_parents)
c66b6c0 Merge branch 'master' into js/fmt-patch
Junio C Hamano authored
545 show_parents(commit, abbrev_commit);
91b849b Jay Soffian log --children
jaysoffian authored
546 if (opt->children.name)
547 show_children(opt, commit, abbrev_commit);
73f0a15 Merge branch 'js/fmt-patch'
Junio C Hamano authored
548 if (parent)
3eefc18 Tentative built-in format-patch.
Junio C Hamano authored
549 printf(" (from %s)",
7fcda92 trast log: do not print ellipses with --abbrev-commit
trast authored
550 find_unique_abbrev(parent->object.sha1,
3eefc18 Tentative built-in format-patch.
Junio C Hamano authored
551 abbrev_commit));
9d3f002 Nguyễn Thái Ngọc Duy pretty: share code between format_decoration and show_decorations
pclouds authored
552 fputs(diff_get_color_opt(&opt->diffopt, DIFF_RESET), stdout);
0f3a290 Linus Torvalds Add a 'source' decorator for commits
torvalds authored
553 show_decorations(opt, commit);
7fefda5 Adam Simpkins log and rev-list: add --graph option
simpkins authored
554 if (opt->commit_format == CMIT_FMT_ONELINE) {
555 putchar(' ');
556 } else {
557 putchar('\n');
558 graph_show_oneline(opt->graph);
559 }
903b45f git-log -g --pretty=oneline should display the reflog message
Nicolas Pitre authored
560 if (opt->reflog_info) {
7fefda5 Adam Simpkins log and rev-list: add --graph option
simpkins authored
561 /*
562 * setup_revisions() ensures that opt->reflog_info
563 * and opt->graph cannot both be set,
564 * so we don't need to worry about printing the
565 * graph info here.
566 */
4d12a47 Fix --walk-reflog with --pretty=oneline
Junio C Hamano authored
567 show_reflog_message(opt->reflog_info,
55ccf85 Junio C Hamano reflog-walk: tell explicit --date=default from not having --date at all
authored
568 opt->commit_format == CMIT_FMT_ONELINE,
569 opt->date_mode,
570 opt->date_mode_explicit);
0286565 Adam Simpkins Remove dead code: show_log() sep argument and diff_options.msg_sep
simpkins authored
571 if (opt->commit_format == CMIT_FMT_ONELINE)
903b45f git-log -g --pretty=oneline should display the reflog message
Nicolas Pitre authored
572 return;
573 }
3eefc18 Tentative built-in format-patch.
Junio C Hamano authored
574 }
9153983 Log message printout cleanups
Linus Torvalds authored
575
824958e Junio C Hamano log-tree: show mergetag in log --show-signature output
authored
576 if (opt->show_signature) {
0c37f1f Junio C Hamano log: --show-signature
authored
577 show_signature(opt, commit);
824958e Junio C Hamano log-tree: show mergetag in log --show-signature output
authored
578 show_mergetag(opt, commit);
579 }
0c37f1f Junio C Hamano log: --show-signature
authored
580
8597ea3 Jeff King commit: record buffer length in cache
peff authored
581 if (!get_cached_commit_buffer(commit, NULL))
3131b71 Linus Torvalds Add "--show-all" revision walker flag for debugging
torvalds authored
582 return;
583
ddf333f Junio C Hamano pretty: prepare notes message at a centralized place
authored
584 if (opt->show_notes) {
585 int raw;
586 struct strbuf notebuf = STRBUF_INIT;
587
588 raw = (opt->commit_format == CMIT_FMT_USERFORMAT);
589 format_display_notes(commit->object.sha1, &notebuf,
590 get_log_output_encoding(), raw);
591 ctx.notes_message = notebuf.len
592 ? strbuf_detach(&notebuf, NULL)
593 : xcalloc(1, 1);
594 }
595
9153983 Log message printout cleanups
Linus Torvalds authored
596 /*
597 * And then the pretty-printed message itself
598 */
5289c56 Nguyễn Thái Ngọc Duy format-patch: update append_signoff prototype
pclouds authored
599 if (ctx.need_8bit_cte >= 0 && opt->add_signoff)
600 ctx.need_8bit_cte =
601 has_non_ascii(fmt_name(getenv("GIT_COMMITTER_NAME"),
602 getenv("GIT_COMMITTER_EMAIL")));
dd2e794 trast Refactor pretty_print_commit arguments into a struct
trast authored
603 ctx.date_mode = opt->date_mode;
f026c75 Jeff King log: respect date_mode_explicit with --format:%gd
peff authored
604 ctx.date_mode_explicit = opt->date_mode_explicit;
dd2e794 trast Refactor pretty_print_commit arguments into a struct
trast authored
605 ctx.abbrev = opt->diffopt.abbrev;
606 ctx.after_subject = extra_headers;
9553d2b Jeff King format-patch: preserve subject newlines with -k
peff authored
607 ctx.preserve_subject = opt->preserve_subject;
8f8f547 trast Introduce new pretty formats %g[sdD] for reflog information
trast authored
608 ctx.reflog_info = opt->reflog_info;
6bf1394 Jeff King clean up calling conventions for pretty.c functions
peff authored
609 ctx.fmt = opt->commit_format;
0e2913b Antoine Pelisse mailmap: add mailmap structure to rev_info and pp
apelisse authored
610 ctx.mailmap = opt->mailmap;
3082517 Junio C Hamano log --format: teach %C(auto,black) to respect color config
authored
611 ctx.color = opt->diffopt.use_color;
ecaee80 Alexey Shumkin pretty: --format output should honor logOutputEncoding
ashumkin authored
612 ctx.output_encoding = get_log_output_encoding();
a908047 Jeff King teach format-patch to place other authors into in-body "From"
peff authored
613 if (opt->from_ident.mail_begin && opt->from_ident.name_begin)
614 ctx.from_ident = &opt->from_ident;
6bf1394 Jeff King clean up calling conventions for pretty.c functions
peff authored
615 pretty_print_commit(&ctx, commit, &msgbuf);
212620f Junio C Hamano format-patch: append --signature after notes
authored
616
617 if (opt->add_signoff)
5289c56 Nguyễn Thái Ngọc Duy format-patch: update append_signoff prototype
pclouds authored
618 append_signoff(&msgbuf, 0, APPEND_SIGNOFF_DEDUP);
212620f Junio C Hamano format-patch: append --signature after notes
authored
619
5a664cf Junio C Hamano pretty_print_commit(): do not append notes message
authored
620 if ((ctx.fmt != CMIT_FMT_USERFORMAT) &&
bd1470b Junio C Hamano format-patch --notes: show notes after three-dashes
authored
621 ctx.notes_message && *ctx.notes_message) {
622 if (ctx.fmt == CMIT_FMT_EMAIL) {
623 strbuf_addstr(&msgbuf, "---\n");
624 opt->shown_dashes = 1;
625 }
5a664cf Junio C Hamano pretty_print_commit(): do not append notes message
authored
626 strbuf_addstr(&msgbuf, ctx.notes_message);
bd1470b Junio C Hamano format-patch --notes: show notes after three-dashes
authored
627 }
cf2251b format-patch --signoff
Junio C Hamano authored
628
7fefda5 Adam Simpkins log and rev-list: add --graph option
simpkins authored
629 if (opt->show_log_size) {
674d172 Pierre Habouzit Rework pretty_print_commit to use strbufs instead of custom buffers.
MadCoder authored
630 printf("log size %i\n", (int)msgbuf.len);
7fefda5 Adam Simpkins log and rev-list: add --graph option
simpkins authored
631 graph_show_oneline(opt->graph);
632 }
9fa3465 Marco Costalba Add --log-size to git log to print message size
mcostalba authored
633
7fefda5 Adam Simpkins log and rev-list: add --graph option
simpkins authored
634 /*
635 * Set opt->missing_newline if msgbuf doesn't
636 * end in a newline (including if it is empty)
637 */
638 if (!msgbuf.len || msgbuf.buf[msgbuf.len - 1] != '\n')
639 opt->missing_newline = 1;
640 else
641 opt->missing_newline = 0;
642
643 if (opt->graph)
644 graph_show_commit_msg(opt->graph, &msgbuf);
645 else
42c8c74 pretty.c: add %x00 format specifier.
Govind Salinas authored
646 fwrite(msgbuf.buf, sizeof(char), msgbuf.len, stdout);
b9c7d6e Jeff King pretty: make empty userformats truly empty
peff authored
647 if (opt->use_terminator && !commit_format_is_empty(opt->commit_format)) {
7fefda5 Adam Simpkins log and rev-list: add --graph option
simpkins authored
648 if (!opt->missing_newline)
649 graph_show_padding(opt->graph);
3e06530 Jan Krüger log-tree: use custom line terminator in line termination mode
jast authored
650 putchar(opt->diffopt.line_termination);
7fefda5 Adam Simpkins log and rev-list: add --graph option
simpkins authored
651 }
652
674d172 Pierre Habouzit Rework pretty_print_commit to use strbufs instead of custom buffers.
MadCoder authored
653 strbuf_release(&msgbuf);
ddf333f Junio C Hamano pretty: prepare notes message at a centralized place
authored
654 free(ctx.notes_message);
9153983 Log message printout cleanups
Linus Torvalds authored
655 }
656
cd2bdc5 Common option parsing for "git log --diff" and friends
Linus Torvalds authored
657 int log_tree_diff_flush(struct rev_info *opt)
5f1c3f0 log-tree: separate major part of diff-tree.
Junio C Hamano authored
658 {
bd1470b Junio C Hamano format-patch --notes: show notes after three-dashes
authored
659 opt->shown_dashes = 0;
5f1c3f0 log-tree: separate major part of diff-tree.
Junio C Hamano authored
660 diffcore_std(&opt->diffopt);
9153983 Log message printout cleanups
Linus Torvalds authored
661
5f1c3f0 log-tree: separate major part of diff-tree.
Junio C Hamano authored
662 if (diff_queue_is_empty()) {
663 int saved_fmt = opt->diffopt.output_format;
664 opt->diffopt.output_format = DIFF_FORMAT_NO_OUTPUT;
665 diff_flush(&opt->diffopt);
666 opt->diffopt.output_format = saved_fmt;
667 return 0;
668 }
9153983 Log message printout cleanups
Linus Torvalds authored
669
3969cf7 Fix some more diff options changes.
Junio C Hamano authored
670 if (opt->loginfo && !opt->no_commit_id) {
0286565 Adam Simpkins Remove dead code: show_log() sep argument and diff_options.msg_sep
simpkins authored
671 show_log(opt);
304b5af Linus Torvalds Clean up "git log" format with DIFF_FORMAT_NO_OUTPUT
torvalds authored
672 if ((opt->diffopt.output_format & ~DIFF_FORMAT_NO_OUTPUT) &&
673 opt->verbose_header &&
b9c7d6e Jeff King pretty: make empty userformats truly empty
peff authored
674 opt->commit_format != CMIT_FMT_ONELINE &&
675 !commit_format_is_empty(opt->commit_format)) {
1d34c50 Junio C Hamano format-patch: add a blank line between notes and diffstat
authored
676 /*
677 * When showing a verbose header (i.e. log message),
678 * and not in --pretty=oneline format, we would want
679 * an extra newline between the end of log and the
680 * diff/diffstat output for readability.
681 */
3969cf7 Fix some more diff options changes.
Junio C Hamano authored
682 int pch = DIFF_FORMAT_DIFFSTAT | DIFF_FORMAT_PATCH;
81bd1b2 byang Output the graph columns at the end of the commit message
byang authored
683 if (opt->diffopt.output_prefix) {
684 struct strbuf *msg = NULL;
685 msg = opt->diffopt.output_prefix(&opt->diffopt,
686 opt->diffopt.output_prefix_data);
687 fwrite(msg->buf, msg->len, 1, stdout);
688 }
1d34c50 Junio C Hamano format-patch: add a blank line between notes and diffstat
authored
689
690 /*
691 * We may have shown three-dashes line early
692 * between notes and the log message, in which
693 * case we only want a blank line after the
694 * notes without (an extra) three-dashes line.
695 * Otherwise, we show the three-dashes line if
696 * we are showing the patch with diffstat, but
697 * in that case, there is no extra blank line
698 * after the three-dashes line.
699 */
700 if (!opt->shown_dashes &&
701 (pch & opt->diffopt.output_format) == pch)
702 printf("---");
703 putchar('\n');
3969cf7 Fix some more diff options changes.
Junio C Hamano authored
704 }
705 }
5f1c3f0 log-tree: separate major part of diff-tree.
Junio C Hamano authored
706 diff_flush(&opt->diffopt);
707 return 1;
708 }
709
cd2bdc5 Common option parsing for "git log --diff" and friends
Linus Torvalds authored
710 static int do_diff_combined(struct rev_info *opt, struct commit *commit)
5f1c3f0 log-tree: separate major part of diff-tree.
Junio C Hamano authored
711 {
8288929 pass struct commit to diff_tree_combined_merge()
René Scharfe authored
712 diff_tree_combined_merge(commit, opt->dense_combined_merges, opt);
9153983 Log message printout cleanups
Linus Torvalds authored
713 return !opt->loginfo;
5f1c3f0 log-tree: separate major part of diff-tree.
Junio C Hamano authored
714 }
715
9153983 Log message printout cleanups
Linus Torvalds authored
716 /*
717 * Show the diff of a commit.
718 *
719 * Return true if we printed any log info messages
720 */
721 static int log_tree_diff(struct rev_info *opt, struct commit *commit, struct log_info *log)
5f1c3f0 log-tree: separate major part of diff-tree.
Junio C Hamano authored
722 {
9153983 Log message printout cleanups
Linus Torvalds authored
723 int showed_log;
5f1c3f0 log-tree: separate major part of diff-tree.
Junio C Hamano authored
724 struct commit_list *parents;
d1b9b76 trast Avoid loading commits twice in log with diffs
trast authored
725 unsigned const char *sha1;
5f1c3f0 log-tree: separate major part of diff-tree.
Junio C Hamano authored
726
84102a3 Peter Valdemar Mørch Teach git log --exit-code to return an appropriate exit code
pmorch authored
727 if (!opt->diff && !DIFF_OPT_TST(&opt->diffopt, EXIT_WITH_STATUS))
9153983 Log message printout cleanups
Linus Torvalds authored
728 return 0;
729
7059dcc Jeff King log_tree_diff: die when we fail to parse a commit
peff authored
730 parse_commit_or_die(commit);
d1b9b76 trast Avoid loading commits twice in log with diffs
trast authored
731 sha1 = commit->tree->object.sha1;
732
5f1c3f0 log-tree: separate major part of diff-tree.
Junio C Hamano authored
733 /* Root commit? */
53d00b3 log: use true parents for diff even when rewriting
Thomas Rast authored
734 parents = get_saved_parents(opt, commit);
9153983 Log message printout cleanups
Linus Torvalds authored
735 if (!parents) {
2b60356 Make git-cherry handle root trees
Rene Scharfe authored
736 if (opt->show_root_diff) {
737 diff_root_tree_sha1(sha1, "", &opt->diffopt);
738 log_tree_diff_flush(opt);
739 }
9153983 Log message printout cleanups
Linus Torvalds authored
740 return !opt->loginfo;
5f1c3f0 log-tree: separate major part of diff-tree.
Junio C Hamano authored
741 }
742
743 /* More than one parent? */
9153983 Log message printout cleanups
Linus Torvalds authored
744 if (parents && parents->next) {
5f1c3f0 log-tree: separate major part of diff-tree.
Junio C Hamano authored
745 if (opt->ignore_merges)
746 return 0;
747 else if (opt->combine_merges)
748 return do_diff_combined(opt, commit);
88d9d45 git log -p -m: document -m and honor --first-parent
Petr Baudis authored
749 else if (opt->first_parent_only) {
750 /*
751 * Generate merge log entry only for the first
752 * parent, showing summary diff of the others
753 * we merged _in_.
754 */
7059dcc Jeff King log_tree_diff: die when we fail to parse a commit
peff authored
755 parse_commit_or_die(parents->item);
d1b9b76 trast Avoid loading commits twice in log with diffs
trast authored
756 diff_tree_sha1(parents->item->tree->object.sha1,
757 sha1, "", &opt->diffopt);
88d9d45 git log -p -m: document -m and honor --first-parent
Petr Baudis authored
758 log_tree_diff_flush(opt);
759 return !opt->loginfo;
760 }
9153983 Log message printout cleanups
Linus Torvalds authored
761
762 /* If we show individual diffs, show the parent info */
763 log->parent = parents->item;
5f1c3f0 log-tree: separate major part of diff-tree.
Junio C Hamano authored
764 }
765
9153983 Log message printout cleanups
Linus Torvalds authored
766 showed_log = 0;
767 for (;;) {
5f1c3f0 log-tree: separate major part of diff-tree.
Junio C Hamano authored
768 struct commit *parent = parents->item;
769
7059dcc Jeff King log_tree_diff: die when we fail to parse a commit
peff authored
770 parse_commit_or_die(parent);
d1b9b76 trast Avoid loading commits twice in log with diffs
trast authored
771 diff_tree_sha1(parent->tree->object.sha1,
772 sha1, "", &opt->diffopt);
9153983 Log message printout cleanups
Linus Torvalds authored
773 log_tree_diff_flush(opt);
774
775 showed_log |= !opt->loginfo;
776
777 /* Set up the log info for the next parent, if any.. */
778 parents = parents->next;
779 if (!parents)
780 break;
781 log->parent = parents->item;
782 opt->loginfo = log;
783 }
784 return showed_log;
785 }
786
787 int log_tree_commit(struct rev_info *opt, struct commit *commit)
788 {
789 struct log_info log;
3eefc18 Tentative built-in format-patch.
Junio C Hamano authored
790 int shown;
9153983 Log message printout cleanups
Linus Torvalds authored
791
792 log.commit = commit;
793 log.parent = NULL;
794 opt->loginfo = &log;
795
12da1d1 trast Implement line-history search (git log -L)
trast authored
796 if (opt->line_level_traverse)
797 return line_log_print(opt, commit);
798
1b32dec Nguyễn Thái Ngọc Duy log: add --show-linear-break to help see non-linear history
pclouds authored
799 if (opt->track_linear && !opt->linear && !opt->reverse_output_stage)
800 printf("\n%s\n", opt->break_bar);
3eefc18 Tentative built-in format-patch.
Junio C Hamano authored
801 shown = log_tree_diff(opt, commit, &log);
802 if (!shown && opt->loginfo && opt->always_show_header) {
9153983 Log message printout cleanups
Linus Torvalds authored
803 log.parent = NULL;
0286565 Adam Simpkins Remove dead code: show_log() sep argument and diff_options.msg_sep
simpkins authored
804 show_log(opt);
3eefc18 Tentative built-in format-patch.
Junio C Hamano authored
805 shown = 1;
5f1c3f0 log-tree: separate major part of diff-tree.
Junio C Hamano authored
806 }
1b32dec Nguyễn Thái Ngọc Duy log: add --show-linear-break to help see non-linear history
pclouds authored
807 if (opt->track_linear && !opt->linear && opt->reverse_output_stage)
808 printf("\n%s\n", opt->break_bar);
9153983 Log message printout cleanups
Linus Torvalds authored
809 opt->loginfo = NULL;
06f59e9 Theodore Ts'o Don't fflush(stdout) when it's not helpful
tytso authored
810 maybe_flush_or_die(stdout, "stdout");
3eefc18 Tentative built-in format-patch.
Junio C Hamano authored
811 return shown;
5f1c3f0 log-tree: separate major part of diff-tree.
Junio C Hamano authored
812 }
Something went wrong with that request. Please try again.