Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

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