Skip to content
Newer
Older
100644 670 lines (603 sloc) 17.2 KB
5f1c3f0 log-tree: separate major part of diff-tree.
Junio C Hamano authored Apr 9, 2006
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 Sep 4, 2008
4 #include "tag.h"
7fefda5 @simpkins log and rev-list: add --graph option
simpkins authored May 4, 2008
5 #include "graph.h"
5f1c3f0 log-tree: separate major part of diff-tree.
Junio C Hamano authored Apr 9, 2006
6 #include "log-tree.h"
8860fd4 @dscho Teach the revision walker to walk by reflogs with --walk-reflogs
dscho authored Jan 11, 2007
7 #include "reflog-walk.h"
cab4feb move load_ref_decorations() to log-tree.c and export it
René Scharfe authored Sep 4, 2008
8 #include "refs.h"
b079c50 @trast format-patch: track several references
trast authored Feb 19, 2009
9 #include "string-list.h"
67a4b58 @nazri log --decorate: Colorize commit decorations
nazri authored Jun 19, 2010
10 #include "color.h"
5f1c3f0 log-tree: separate major part of diff-tree.
Junio C Hamano authored Apr 9, 2006
11
ca135e7 @torvalds Add support for "commit name decorations" to log family of commands
torvalds authored Apr 16, 2007
12 struct decoration name_decoration = { "object names" };
13
a752412 @nazri log-tree.c: Use struct name_decoration's type for classifying decoration
nazri authored Jun 19, 2010
14 enum decoration_type {
15 DECORATION_NONE = 0,
16 DECORATION_REF_LOCAL,
17 DECORATION_REF_REMOTE,
18 DECORATION_REF_TAG,
19 DECORATION_REF_STASH,
20 DECORATION_REF_HEAD,
21 };
22
67a4b58 @nazri log --decorate: Colorize commit decorations
nazri authored Jun 19, 2010
23 static char decoration_colors[][COLOR_MAXLEN] = {
24 GIT_COLOR_RESET,
25 GIT_COLOR_BOLD_GREEN, /* REF_LOCAL */
26 GIT_COLOR_BOLD_RED, /* REF_REMOTE */
27 GIT_COLOR_BOLD_YELLOW, /* REF_TAG */
28 GIT_COLOR_BOLD_MAGENTA, /* REF_STASH */
29 GIT_COLOR_BOLD_CYAN, /* REF_HEAD */
30 };
31
32 static const char *decorate_get_color(int decorate_use_color, enum decoration_type ix)
33 {
34 if (decorate_use_color)
35 return decoration_colors[ix];
36 return "";
37 }
38
5e11bee @nazri Allow customizable commit decorations colors
nazri authored Jun 24, 2010
39 static int parse_decorate_color_slot(const char *slot)
40 {
41 /*
42 * We're comparing with 'ignore-case' on
43 * (because config.c sets them all tolower),
44 * but let's match the letters in the literal
45 * string values here with how they are
46 * documented in Documentation/config.txt, for
47 * consistency.
48 *
49 * We love being consistent, don't we?
50 */
51 if (!strcasecmp(slot, "branch"))
52 return DECORATION_REF_LOCAL;
53 if (!strcasecmp(slot, "remoteBranch"))
54 return DECORATION_REF_REMOTE;
55 if (!strcasecmp(slot, "tag"))
56 return DECORATION_REF_TAG;
57 if (!strcasecmp(slot, "stash"))
58 return DECORATION_REF_STASH;
59 if (!strcasecmp(slot, "HEAD"))
60 return DECORATION_REF_HEAD;
61 return -1;
62 }
63
64 int parse_decorate_color_config(const char *var, const int ofs, const char *value)
65 {
66 int slot = parse_decorate_color_slot(var + ofs);
67 if (slot < 0)
68 return 0;
69 if (!value)
70 return config_error_nonbool(var);
71 color_parse(value, var, decoration_colors[slot]);
72 return 0;
73 }
74
67a4b58 @nazri log --decorate: Colorize commit decorations
nazri authored Jun 19, 2010
75 /*
76 * log-tree.c uses DIFF_OPT_TST for determining whether to use color
77 * for showing the commit sha1, use the same check for --decorate
78 */
79 #define decorate_get_color_opt(o, ix) \
80 decorate_get_color(DIFF_OPT_TST((o), COLOR_DIFF), ix)
81
a752412 @nazri log-tree.c: Use struct name_decoration's type for classifying decoration
nazri authored Jun 19, 2010
82 static 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 Sep 4, 2008
83 {
84 int nlen = strlen(name);
a752412 @nazri log-tree.c: Use struct name_decoration's type for classifying decoration
nazri authored Jun 19, 2010
85 struct name_decoration *res = xmalloc(sizeof(struct name_decoration) + nlen);
86 memcpy(res->name, name, nlen + 1);
87 res->type = type;
cab4feb move load_ref_decorations() to log-tree.c and export it
René Scharfe authored Sep 4, 2008
88 res->next = add_decoration(&name_decoration, obj, res);
89 }
90
91 static int add_ref_decoration(const char *refname, const unsigned char *sha1, int flags, void *cb_data)
92 {
93 struct object *obj = parse_object(sha1);
a752412 @nazri log-tree.c: Use struct name_decoration's type for classifying decoration
nazri authored Jun 19, 2010
94 enum decoration_type type = DECORATION_NONE;
cab4feb move load_ref_decorations() to log-tree.c and export it
René Scharfe authored Sep 4, 2008
95 if (!obj)
96 return 0;
a752412 @nazri log-tree.c: Use struct name_decoration's type for classifying decoration
nazri authored Jun 19, 2010
97
98 if (!prefixcmp(refname, "refs/heads"))
99 type = DECORATION_REF_LOCAL;
100 else if (!prefixcmp(refname, "refs/remotes"))
101 type = DECORATION_REF_REMOTE;
102 else if (!prefixcmp(refname, "refs/tags"))
103 type = DECORATION_REF_TAG;
104 else if (!prefixcmp(refname, "refs/stash"))
105 type = DECORATION_REF_STASH;
106 else if (!prefixcmp(refname, "HEAD"))
107 type = DECORATION_REF_HEAD;
108
33e7018 @hjemli git-log: allow --decorate[=short|full]
hjemli authored Aug 15, 2009
109 if (!cb_data || *(int *)cb_data == DECORATE_SHORT_REFS)
110 refname = prettify_refname(refname);
a752412 @nazri log-tree.c: Use struct name_decoration's type for classifying decoration
nazri authored Jun 19, 2010
111 add_name_decoration(type, refname, obj);
cab4feb move load_ref_decorations() to log-tree.c and export it
René Scharfe authored Sep 4, 2008
112 while (obj->type == OBJ_TAG) {
113 obj = ((struct tag *)obj)->tagged;
114 if (!obj)
115 break;
a752412 @nazri log-tree.c: Use struct name_decoration's type for classifying decoration
nazri authored Jun 19, 2010
116 add_name_decoration(DECORATION_REF_TAG, refname, obj);
cab4feb move load_ref_decorations() to log-tree.c and export it
René Scharfe authored Sep 4, 2008
117 }
118 return 0;
119 }
120
33e7018 @hjemli git-log: allow --decorate[=short|full]
hjemli authored Aug 15, 2009
121 void load_ref_decorations(int flags)
cab4feb move load_ref_decorations() to log-tree.c and export it
René Scharfe authored Sep 4, 2008
122 {
123 static int loaded;
124 if (!loaded) {
125 loaded = 1;
33e7018 @hjemli git-log: allow --decorate[=short|full]
hjemli authored Aug 15, 2009
126 for_each_ref(add_ref_decoration, &flags);
77abcbd @trast Let --decorate show HEAD position
trast authored Oct 12, 2009
127 head_ref(add_ref_decoration, &flags);
cab4feb move load_ref_decorations() to log-tree.c and export it
René Scharfe authored Sep 4, 2008
128 }
129 }
130
c8c893c Fix "git-log --parents" breakage post v1.3.0
Linus Torvalds authored May 3, 2006
131 static void show_parents(struct commit *commit, int abbrev)
132 {
133 struct commit_list *p;
134 for (p = commit->parents; p ; p = p->next) {
135 struct commit *parent = p->item;
7fcda92 @trast log: do not print ellipses with --abbrev-commit
trast authored Feb 13, 2009
136 printf(" %s", find_unique_abbrev(parent->object.sha1, abbrev));
c8c893c Fix "git-log --parents" breakage post v1.3.0
Linus Torvalds authored May 3, 2006
137 }
138 }
139
0f3a290 @torvalds Add a 'source' decorator for commits
torvalds authored Oct 27, 2008
140 void show_decorations(struct rev_info *opt, struct commit *commit)
ca135e7 @torvalds Add support for "commit name decorations" to log family of commands
torvalds authored Apr 16, 2007
141 {
142 const char *prefix;
143 struct name_decoration *decoration;
67a4b58 @nazri log --decorate: Colorize commit decorations
nazri authored Jun 19, 2010
144 const char *color_commit =
145 diff_get_color_opt(&opt->diffopt, DIFF_COMMIT);
146 const char *color_reset =
147 decorate_get_color_opt(&opt->diffopt, DECORATION_NONE);
ca135e7 @torvalds Add support for "commit name decorations" to log family of commands
torvalds authored Apr 16, 2007
148
0f3a290 @torvalds Add a 'source' decorator for commits
torvalds authored Oct 27, 2008
149 if (opt->show_source && commit->util)
8c4021a @torvalds Fix machine-parseability of 'git log --source'
torvalds authored Nov 15, 2008
150 printf("\t%s", (char *) commit->util);
d467a52 @torvalds Make '--decorate' set an explicit 'show_decorations' flag
torvalds authored Nov 3, 2008
151 if (!opt->show_decorations)
152 return;
ca135e7 @torvalds Add support for "commit name decorations" to log family of commands
torvalds authored Apr 16, 2007
153 decoration = lookup_decoration(&name_decoration, &commit->object);
154 if (!decoration)
155 return;
156 prefix = " (";
157 while (decoration) {
a752412 @nazri log-tree.c: Use struct name_decoration's type for classifying decoration
nazri authored Jun 19, 2010
158 printf("%s", prefix);
67a4b58 @nazri log --decorate: Colorize commit decorations
nazri authored Jun 19, 2010
159 fputs(decorate_get_color_opt(&opt->diffopt, decoration->type),
160 stdout);
a752412 @nazri log-tree.c: Use struct name_decoration's type for classifying decoration
nazri authored Jun 19, 2010
161 if (decoration->type == DECORATION_REF_TAG)
67a4b58 @nazri log --decorate: Colorize commit decorations
nazri authored Jun 19, 2010
162 fputs("tag: ", stdout);
a752412 @nazri log-tree.c: Use struct name_decoration's type for classifying decoration
nazri authored Jun 19, 2010
163 printf("%s", decoration->name);
67a4b58 @nazri log --decorate: Colorize commit decorations
nazri authored Jun 19, 2010
164 fputs(color_reset, stdout);
165 fputs(color_commit, stdout);
ca135e7 @torvalds Add support for "commit name decorations" to log family of commands
torvalds authored Apr 16, 2007
166 prefix = ", ";
167 decoration = decoration->next;
168 }
169 putchar(')');
170 }
171
fc1c75e log-tree.c: cleanup a bit append_signoff()
Franck Bui-Huu authored Aug 29, 2006
172 /*
173 * Search for "^[-A-Za-z]+: [^@]+@" pattern. It usually matches
174 * Signed-off-by: and Acked-by: lines.
175 */
176 static int detect_any_signoff(char *letter, int size)
177 {
fd13b21 @d0k Move local variables to narrower scopes
d0k authored Mar 7, 2009
178 char *cp;
fc1c75e log-tree.c: cleanup a bit append_signoff()
Franck Bui-Huu authored Aug 29, 2006
179 int seen_colon = 0;
180 int seen_at = 0;
181 int seen_name = 0;
182 int seen_head = 0;
183
184 cp = letter + size;
fd13b21 @d0k Move local variables to narrower scopes
d0k authored Mar 7, 2009
185 while (letter <= --cp && *cp == '\n')
fc1c75e log-tree.c: cleanup a bit append_signoff()
Franck Bui-Huu authored Aug 29, 2006
186 continue;
187
188 while (letter <= cp) {
fd13b21 @d0k Move local variables to narrower scopes
d0k authored Mar 7, 2009
189 char ch = *cp--;
fc1c75e log-tree.c: cleanup a bit append_signoff()
Franck Bui-Huu authored Aug 29, 2006
190 if (ch == '\n')
191 break;
192
193 if (!seen_at) {
194 if (ch == '@')
195 seen_at = 1;
196 continue;
197 }
198 if (!seen_colon) {
199 if (ch == '@')
200 return 0;
201 else if (ch == ':')
202 seen_colon = 1;
203 else
204 seen_name = 1;
205 continue;
206 }
207 if (('A' <= ch && ch <= 'Z') ||
208 ('a' <= ch && ch <= 'z') ||
209 ch == '-') {
210 seen_head = 1;
211 continue;
212 }
213 /* no empty last line doesn't match */
214 return 0;
215 }
216 return seen_head && seen_name;
217 }
218
674d172 Rework pretty_print_commit to use strbufs instead of custom buffers.
Pierre Habouzit authored Sep 10, 2007
219 static void append_signoff(struct strbuf *sb, const char *signoff)
cf2251b format-patch --signoff
Junio C Hamano authored May 31, 2006
220 {
221 static const char signed_off_by[] = "Signed-off-by: ";
80583c0 @gitster Lift 16kB limit of log message output
gitster authored Jun 11, 2007
222 size_t signoff_len = strlen(signoff);
fc1c75e log-tree.c: cleanup a bit append_signoff()
Franck Bui-Huu authored Aug 29, 2006
223 int has_signoff = 0;
80583c0 @gitster Lift 16kB limit of log message output
gitster authored Jun 11, 2007
224 char *cp;
cf2251b format-patch --signoff
Junio C Hamano authored May 31, 2006
225
674d172 Rework pretty_print_commit to use strbufs instead of custom buffers.
Pierre Habouzit authored Sep 10, 2007
226 cp = sb->buf;
cf2251b format-patch --signoff
Junio C Hamano authored May 31, 2006
227
228 /* First see if we already have the sign-off by the signer */
fc1c75e log-tree.c: cleanup a bit append_signoff()
Franck Bui-Huu authored Aug 29, 2006
229 while ((cp = strstr(cp, signed_off_by))) {
230
231 has_signoff = 1;
232
cf2251b format-patch --signoff
Junio C Hamano authored May 31, 2006
233 cp += strlen(signed_off_by);
674d172 Rework pretty_print_commit to use strbufs instead of custom buffers.
Pierre Habouzit authored Sep 10, 2007
234 if (cp + signoff_len >= sb->buf + sb->len)
fc1c75e log-tree.c: cleanup a bit append_signoff()
Franck Bui-Huu authored Aug 29, 2006
235 break;
236 if (strncmp(cp, signoff, signoff_len))
237 continue;
238 if (!isspace(cp[signoff_len]))
239 continue;
240 /* we already have him */
674d172 Rework pretty_print_commit to use strbufs instead of custom buffers.
Pierre Habouzit authored Sep 10, 2007
241 return;
cf2251b format-patch --signoff
Junio C Hamano authored May 31, 2006
242 }
243
fc1c75e log-tree.c: cleanup a bit append_signoff()
Franck Bui-Huu authored Aug 29, 2006
244 if (!has_signoff)
674d172 Rework pretty_print_commit to use strbufs instead of custom buffers.
Pierre Habouzit authored Sep 10, 2007
245 has_signoff = detect_any_signoff(sb->buf, sb->len);
fc1c75e log-tree.c: cleanup a bit append_signoff()
Franck Bui-Huu authored Aug 29, 2006
246
247 if (!has_signoff)
674d172 Rework pretty_print_commit to use strbufs instead of custom buffers.
Pierre Habouzit authored Sep 10, 2007
248 strbuf_addch(sb, '\n');
c35f4c3 Add a newline before appending "Signed-off-by: " line
Franck Bui-Huu authored Aug 13, 2006
249
674d172 Rework pretty_print_commit to use strbufs instead of custom buffers.
Pierre Habouzit authored Sep 10, 2007
250 strbuf_addstr(sb, signed_off_by);
251 strbuf_add(sb, signoff, signoff_len);
252 strbuf_addch(sb, '\n');
cf2251b format-patch --signoff
Junio C Hamano authored May 31, 2006
253 }
254
e00de24 @dscho format-patch -n: make sorting easier by padding number
dscho authored Feb 9, 2007
255 static unsigned int digits_in_number(unsigned int number)
256 {
257 unsigned int i = 10, result = 1;
258 while (i <= number) {
259 i *= 10;
260 result++;
261 }
262 return result;
263 }
264
6fa8e62 @bebarino format-patch: move get_patch_filename() into log-tree
bebarino authored Mar 22, 2009
265 void get_patch_filename(struct commit *commit, int nr, const char *suffix,
266 struct strbuf *buf)
267 {
268 int suffix_len = strlen(suffix) + 1;
269 int start_len = buf->len;
270
271 strbuf_addf(buf, commit ? "%04d-" : "%d", nr);
272 if (commit) {
b09b868 @chriscool log-tree: fix patch filename computation in "git format-patch"
chriscool authored Mar 27, 2009
273 int max_len = start_len + FORMAT_PATCH_NAME_MAX - suffix_len;
dd2e794 @trast Refactor pretty_print_commit arguments into a struct
trast authored Oct 19, 2009
274 struct pretty_print_context ctx = {0};
275 ctx.date_mode = DATE_NORMAL;
b09b868 @chriscool log-tree: fix patch filename computation in "git format-patch"
chriscool authored Mar 27, 2009
276
dd2e794 @trast Refactor pretty_print_commit arguments into a struct
trast authored Oct 19, 2009
277 format_commit_message(commit, "%f", buf, &ctx);
b09b868 @chriscool log-tree: fix patch filename computation in "git format-patch"
chriscool authored Mar 27, 2009
278 if (max_len < buf->len)
279 strbuf_setlen(buf, max_len);
280 strbuf_addstr(buf, suffix);
6fa8e62 @bebarino format-patch: move get_patch_filename() into log-tree
bebarino authored Mar 23, 2009
281 }
282 }
283
108dab2 @bebarino format-patch: --attach/inline uses filename instead of SHA1
bebarino authored Mar 22, 2009
284 void log_write_email_headers(struct rev_info *opt, struct commit *commit,
267123b @gitster Merge branch 'maint'
gitster authored Mar 15, 2008
285 const char **subject_p,
286 const char **extra_headers_p,
287 int *need_8bit_cte_p)
b02bd65 Export some email and pretty-printing functions
Daniel Barkalow authored Feb 18, 2008
288 {
289 const char *subject = NULL;
290 const char *extra_headers = opt->extra_headers;
108dab2 @bebarino format-patch: --attach/inline uses filename instead of SHA1
bebarino authored Mar 23, 2009
291 const char *name = sha1_to_hex(commit->object.sha1);
267123b @gitster Merge branch 'maint'
gitster authored Mar 15, 2008
292
293 *need_8bit_cte_p = 0; /* unknown */
b02bd65 Export some email and pretty-printing functions
Daniel Barkalow authored Feb 19, 2008
294 if (opt->total > 0) {
295 static char buffer[64];
296 snprintf(buffer, sizeof(buffer),
297 "Subject: [%s %0*d/%d] ",
298 opt->subject_prefix,
299 digits_in_number(opt->total),
300 opt->nr, opt->total);
301 subject = buffer;
302 } else if (opt->total == 0 && opt->subject_prefix && *opt->subject_prefix) {
303 static char buffer[256];
304 snprintf(buffer, sizeof(buffer),
305 "Subject: [%s] ",
306 opt->subject_prefix);
307 subject = buffer;
308 } else {
309 subject = "Subject: ";
310 }
311
312 printf("From %s Mon Sep 17 00:00:00 2001\n", name);
7fefda5 @simpkins log and rev-list: add --graph option
simpkins authored May 4, 2008
313 graph_show_oneline(opt->graph);
314 if (opt->message_id) {
b02bd65 Export some email and pretty-printing functions
Daniel Barkalow authored Feb 19, 2008
315 printf("Message-Id: <%s>\n", opt->message_id);
7fefda5 @simpkins log and rev-list: add --graph option
simpkins authored May 4, 2008
316 graph_show_oneline(opt->graph);
317 }
b079c50 @trast format-patch: track several references
trast authored Feb 19, 2009
318 if (opt->ref_message_ids && opt->ref_message_ids->nr > 0) {
319 int i, n;
320 n = opt->ref_message_ids->nr;
321 printf("In-Reply-To: <%s>\n", opt->ref_message_ids->items[n-1].string);
322 for (i = 0; i < n; i++)
323 printf("%s<%s>\n", (i > 0 ? "\t" : "References: "),
324 opt->ref_message_ids->items[i].string);
7fefda5 @simpkins log and rev-list: add --graph option
simpkins authored May 4, 2008
325 graph_show_oneline(opt->graph);
326 }
b02bd65 Export some email and pretty-printing functions
Daniel Barkalow authored Feb 19, 2008
327 if (opt->mime_boundary) {
328 static char subject_buffer[1024];
329 static char buffer[1024];
108dab2 @bebarino format-patch: --attach/inline uses filename instead of SHA1
bebarino authored Mar 23, 2009
330 struct strbuf filename = STRBUF_INIT;
267123b @gitster Merge branch 'maint'
gitster authored Mar 15, 2008
331 *need_8bit_cte_p = -1; /* NEVER */
b02bd65 Export some email and pretty-printing functions
Daniel Barkalow authored Feb 19, 2008
332 snprintf(subject_buffer, sizeof(subject_buffer) - 1,
333 "%s"
334 "MIME-Version: 1.0\n"
335 "Content-Type: multipart/mixed;"
336 " boundary=\"%s%s\"\n"
337 "\n"
338 "This is a multi-part message in MIME "
339 "format.\n"
340 "--%s%s\n"
341 "Content-Type: text/plain; "
342 "charset=UTF-8; format=fixed\n"
343 "Content-Transfer-Encoding: 8bit\n\n",
344 extra_headers ? extra_headers : "",
345 mime_boundary_leader, opt->mime_boundary,
346 mime_boundary_leader, opt->mime_boundary);
347 extra_headers = subject_buffer;
348
108dab2 @bebarino format-patch: --attach/inline uses filename instead of SHA1
bebarino authored Mar 23, 2009
349 get_patch_filename(opt->numbered_files ? NULL : commit, opt->nr,
350 opt->patch_suffix, &filename);
b02bd65 Export some email and pretty-printing functions
Daniel Barkalow authored Feb 19, 2008
351 snprintf(buffer, sizeof(buffer) - 1,
6b2fbaa @kballard format-patch: Produce better output with --inline or --attach
kballard authored Jul 29, 2008
352 "\n--%s%s\n"
b02bd65 Export some email and pretty-printing functions
Daniel Barkalow authored Feb 19, 2008
353 "Content-Type: text/x-patch;"
108dab2 @bebarino format-patch: --attach/inline uses filename instead of SHA1
bebarino authored Mar 23, 2009
354 " name=\"%s\"\n"
b02bd65 Export some email and pretty-printing functions
Daniel Barkalow authored Feb 19, 2008
355 "Content-Transfer-Encoding: 8bit\n"
356 "Content-Disposition: %s;"
108dab2 @bebarino format-patch: --attach/inline uses filename instead of SHA1
bebarino authored Mar 23, 2009
357 " filename=\"%s\"\n\n",
b02bd65 Export some email and pretty-printing functions
Daniel Barkalow authored Feb 19, 2008
358 mime_boundary_leader, opt->mime_boundary,
108dab2 @bebarino format-patch: --attach/inline uses filename instead of SHA1
bebarino authored Mar 23, 2009
359 filename.buf,
b02bd65 Export some email and pretty-printing functions
Daniel Barkalow authored Feb 19, 2008
360 opt->no_inline ? "attachment" : "inline",
108dab2 @bebarino format-patch: --attach/inline uses filename instead of SHA1
bebarino authored Mar 23, 2009
361 filename.buf);
b02bd65 Export some email and pretty-printing functions
Daniel Barkalow authored Feb 19, 2008
362 opt->diffopt.stat_sep = buffer;
108dab2 @bebarino format-patch: --attach/inline uses filename instead of SHA1
bebarino authored Mar 23, 2009
363 strbuf_release(&filename);
b02bd65 Export some email and pretty-printing functions
Daniel Barkalow authored Feb 19, 2008
364 }
365 *subject_p = subject;
366 *extra_headers_p = extra_headers;
367 }
368
0286565 @simpkins Remove dead code: show_log() sep argument and diff_options.msg_sep
simpkins authored Apr 29, 2008
369 void show_log(struct rev_info *opt)
9153983 Log message printout cleanups
Linus Torvalds authored Apr 17, 2006
370 {
f285a2d Replace calls to strbuf_init(&foo, 0) with STRBUF_INIT initializer
Brandon Casey authored Oct 9, 2008
371 struct strbuf msgbuf = STRBUF_INIT;
39bc9a6 @tihirvon Add msg_sep to diff_options
tihirvon authored Jun 25, 2006
372 struct log_info *log = opt->loginfo;
9153983 Log message printout cleanups
Linus Torvalds authored Apr 17, 2006
373 struct commit *commit = log->commit, *parent = log->parent;
374 int abbrev_commit = opt->abbrev_commit ? opt->abbrev : 40;
dd2e794 @trast Refactor pretty_print_commit arguments into a struct
trast authored Oct 19, 2009
375 const char *extra_headers = opt->extra_headers;
376 struct pretty_print_context ctx = {0};
9153983 Log message printout cleanups
Linus Torvalds authored Apr 17, 2006
377
378 opt->loginfo = NULL;
66b2ed0 @gitster Fix "log" family not to be too agressive about showing notes
gitster authored Jan 20, 2010
379 ctx.show_notes = opt->show_notes;
9153983 Log message printout cleanups
Linus Torvalds authored Apr 17, 2006
380 if (!opt->verbose_header) {
7fefda5 @simpkins log and rev-list: add --graph option
simpkins authored May 4, 2008
381 graph_show_commit(opt->graph);
382
7528f27 @simpkins log --graph --left-right: show left/right information in place of '*'
simpkins authored May 25, 2008
383 if (!opt->graph) {
384 if (commit->object.flags & BOUNDARY)
385 putchar('-');
386 else if (commit->object.flags & UNINTERESTING)
387 putchar('^');
388 else if (opt->left_right) {
389 if (commit->object.flags & SYMMETRIC_LEFT)
390 putchar('<');
391 else
392 putchar('>');
393 }
74bd902 Teach all of log family --left-right output.
Junio C Hamano authored Dec 16, 2006
394 }
7fcda92 @trast log: do not print ellipses with --abbrev-commit
trast authored Feb 13, 2009
395 fputs(find_unique_abbrev(commit->object.sha1, abbrev_commit), stdout);
885cf80 @simpkins revision API: split parent rewriting and parent printing options
simpkins authored May 4, 2008
396 if (opt->print_parents)
c8c893c Fix "git-log --parents" breakage post v1.3.0
Linus Torvalds authored May 3, 2006
397 show_parents(commit, abbrev_commit);
0f3a290 @torvalds Add a 'source' decorator for commits
torvalds authored Oct 27, 2008
398 show_decorations(opt, commit);
7fefda5 @simpkins log and rev-list: add --graph option
simpkins authored May 4, 2008
399 if (opt->graph && !graph_is_commit_finished(opt->graph)) {
400 putchar('\n');
401 graph_show_remainder(opt->graph);
402 }
1dcb692 @pugmajere log-tree: show_log() should respect the setting of diffopt->line_term…
pugmajere authored Aug 7, 2006
403 putchar(opt->diffopt.line_termination);
9153983 Log message printout cleanups
Linus Torvalds authored Apr 17, 2006
404 return;
405 }
406
407 /*
8715227 @peff log-tree: fix confusing comment
peff authored Jul 1, 2009
408 * If use_terminator is set, we already handled any record termination
409 * at the end of the last record.
0286565 @simpkins Remove dead code: show_log() sep argument and diff_options.msg_sep
simpkins authored Apr 29, 2008
410 * Otherwise, add a diffopt.line_termination character before all
411 * entries but the first. (IOW, as a separator between entries)
9153983 Log message printout cleanups
Linus Torvalds authored Apr 17, 2006
412 */
7fefda5 @simpkins log and rev-list: add --graph option
simpkins authored May 4, 2008
413 if (opt->shown_one && !opt->use_terminator) {
414 /*
415 * If entries are separated by a newline, the output
416 * should look human-readable. If the last entry ended
417 * with a newline, print the graph output before this
418 * newline. Otherwise it will end up as a completely blank
419 * line and will look like a gap in the graph.
420 *
421 * If the entry separator is not a newline, the output is
422 * primarily intended for programmatic consumption, and we
423 * never want the extra graph output before the entry
424 * separator.
425 */
426 if (opt->diffopt.line_termination == '\n' &&
427 !opt->missing_newline)
428 graph_show_padding(opt->graph);
abd4e22 @torvalds Fix "git log -z" behaviour
torvalds authored Feb 7, 2007
429 putchar(opt->diffopt.line_termination);
7fefda5 @simpkins log and rev-list: add --graph option
simpkins authored May 4, 2008
430 }
9153983 Log message printout cleanups
Linus Torvalds authored Apr 17, 2006
431 opt->shown_one = 1;
432
433 /*
7fefda5 @simpkins log and rev-list: add --graph option
simpkins authored May 4, 2008
434 * If the history graph was requested,
435 * print the graph, up to this commit's line
436 */
437 graph_show_commit(opt->graph);
438
439 /*
9153983 Log message printout cleanups
Linus Torvalds authored Apr 17, 2006
440 * Print header line of header..
441 */
3eefc18 Tentative built-in format-patch.
Junio C Hamano authored Apr 18, 2006
442
596524b @dscho Teach fmt-patch about --numbered
dscho authored May 5, 2006
443 if (opt->commit_format == CMIT_FMT_EMAIL) {
dd2e794 @trast Refactor pretty_print_commit arguments into a struct
trast authored Oct 19, 2009
444 log_write_email_headers(opt, commit, &ctx.subject, &extra_headers,
445 &ctx.need_8bit_cte);
e52a5de @dscho pretty-formats: add 'format:<string>'
dscho authored Feb 23, 2007
446 } else if (opt->commit_format != CMIT_FMT_USERFORMAT) {
8f67f8a Make the diff_options bitfields be an unsigned with explicit masks.
Pierre Habouzit authored Nov 10, 2007
447 fputs(diff_get_color_opt(&opt->diffopt, DIFF_COMMIT), stdout);
74bd902 Teach all of log family --left-right output.
Junio C Hamano authored Dec 16, 2006
448 if (opt->commit_format != CMIT_FMT_ONELINE)
449 fputs("commit ", stdout);
7528f27 @simpkins log --graph --left-right: show left/right information in place of '*'
simpkins authored May 25, 2008
450
451 if (!opt->graph) {
452 if (commit->object.flags & BOUNDARY)
453 putchar('-');
454 else if (commit->object.flags & UNINTERESTING)
455 putchar('^');
456 else if (opt->left_right) {
457 if (commit->object.flags & SYMMETRIC_LEFT)
458 putchar('<');
459 else
460 putchar('>');
461 }
74bd902 Teach all of log family --left-right output.
Junio C Hamano authored Dec 16, 2006
462 }
7fcda92 @trast log: do not print ellipses with --abbrev-commit
trast authored Feb 13, 2009
463 fputs(find_unique_abbrev(commit->object.sha1, abbrev_commit),
74bd902 Teach all of log family --left-right output.
Junio C Hamano authored Dec 16, 2006
464 stdout);
885cf80 @simpkins revision API: split parent rewriting and parent printing options
simpkins authored May 4, 2008
465 if (opt->print_parents)
c66b6c0 Merge branch 'master' into js/fmt-patch
Junio C Hamano authored May 6, 2006
466 show_parents(commit, abbrev_commit);
73f0a15 Merge branch 'js/fmt-patch'
Junio C Hamano authored May 24, 2006
467 if (parent)
3eefc18 Tentative built-in format-patch.
Junio C Hamano authored Apr 18, 2006
468 printf(" (from %s)",
7fcda92 @trast log: do not print ellipses with --abbrev-commit
trast authored Feb 13, 2009
469 find_unique_abbrev(parent->object.sha1,
3eefc18 Tentative built-in format-patch.
Junio C Hamano authored Apr 18, 2006
470 abbrev_commit));
0f3a290 @torvalds Add a 'source' decorator for commits
torvalds authored Oct 27, 2008
471 show_decorations(opt, commit);
8f67f8a Make the diff_options bitfields be an unsigned with explicit masks.
Pierre Habouzit authored Nov 10, 2007
472 printf("%s", diff_get_color_opt(&opt->diffopt, DIFF_RESET));
7fefda5 @simpkins log and rev-list: add --graph option
simpkins authored May 4, 2008
473 if (opt->commit_format == CMIT_FMT_ONELINE) {
474 putchar(' ');
475 } else {
476 putchar('\n');
477 graph_show_oneline(opt->graph);
478 }
903b45f git-log -g --pretty=oneline should display the reflog message
Nicolas Pitre authored Jan 27, 2007
479 if (opt->reflog_info) {
7fefda5 @simpkins log and rev-list: add --graph option
simpkins authored May 4, 2008
480 /*
481 * setup_revisions() ensures that opt->reflog_info
482 * and opt->graph cannot both be set,
483 * so we don't need to worry about printing the
484 * graph info here.
485 */
4d12a47 Fix --walk-reflog with --pretty=oneline
Junio C Hamano authored Jan 20, 2007
486 show_reflog_message(opt->reflog_info,
4e244cb @dscho log --reflog: honour --relative-date
dscho authored Feb 8, 2007
487 opt->commit_format == CMIT_FMT_ONELINE,
f4ea32f @peff improve reflog date/number heuristic
peff authored Sep 24, 2009
488 opt->date_mode_explicit ?
489 opt->date_mode :
490 DATE_NORMAL);
0286565 @simpkins Remove dead code: show_log() sep argument and diff_options.msg_sep
simpkins authored Apr 29, 2008
491 if (opt->commit_format == CMIT_FMT_ONELINE)
903b45f git-log -g --pretty=oneline should display the reflog message
Nicolas Pitre authored Jan 28, 2007
492 return;
493 }
3eefc18 Tentative built-in format-patch.
Junio C Hamano authored Apr 18, 2006
494 }
9153983 Log message printout cleanups
Linus Torvalds authored Apr 17, 2006
495
3131b71 @torvalds Add "--show-all" revision walker flag for debugging
torvalds authored Feb 9, 2008
496 if (!commit->buffer)
497 return;
498
9153983 Log message printout cleanups
Linus Torvalds authored Apr 17, 2006
499 /*
500 * And then the pretty-printed message itself
501 */
dd2e794 @trast Refactor pretty_print_commit arguments into a struct
trast authored Oct 19, 2009
502 if (ctx.need_8bit_cte >= 0)
503 ctx.need_8bit_cte = has_non_ascii(opt->add_signoff);
504 ctx.date_mode = opt->date_mode;
505 ctx.abbrev = opt->diffopt.abbrev;
506 ctx.after_subject = extra_headers;
9553d2b @peff format-patch: preserve subject newlines with -k
peff authored May 26, 2011
507 ctx.preserve_subject = opt->preserve_subject;
8f8f547 @trast Introduce new pretty formats %g[sdD] for reflog information
trast authored Oct 19, 2009
508 ctx.reflog_info = opt->reflog_info;
6bf1394 @peff clean up calling conventions for pretty.c functions
peff authored May 26, 2011
509 ctx.fmt = opt->commit_format;
510 pretty_print_commit(&ctx, commit, &msgbuf);
cf2251b format-patch --signoff
Junio C Hamano authored May 31, 2006
511
512 if (opt->add_signoff)
674d172 Rework pretty_print_commit to use strbufs instead of custom buffers.
Pierre Habouzit authored Sep 10, 2007
513 append_signoff(&msgbuf, opt->add_signoff);
7fefda5 @simpkins log and rev-list: add --graph option
simpkins authored May 4, 2008
514 if (opt->show_log_size) {
674d172 Rework pretty_print_commit to use strbufs instead of custom buffers.
Pierre Habouzit authored Sep 10, 2007
515 printf("log size %i\n", (int)msgbuf.len);
7fefda5 @simpkins log and rev-list: add --graph option
simpkins authored May 4, 2008
516 graph_show_oneline(opt->graph);
517 }
9fa3465 @mcostalba Add --log-size to git log to print message size
mcostalba authored Jul 20, 2007
518
7fefda5 @simpkins log and rev-list: add --graph option
simpkins authored May 4, 2008
519 /*
520 * Set opt->missing_newline if msgbuf doesn't
521 * end in a newline (including if it is empty)
522 */
523 if (!msgbuf.len || msgbuf.buf[msgbuf.len - 1] != '\n')
524 opt->missing_newline = 1;
525 else
526 opt->missing_newline = 0;
527
528 if (opt->graph)
529 graph_show_commit_msg(opt->graph, &msgbuf);
530 else
42c8c74 pretty.c: add %x00 format specifier.
Govind Salinas authored Mar 21, 2008
531 fwrite(msgbuf.buf, sizeof(char), msgbuf.len, stdout);
7fefda5 @simpkins log and rev-list: add --graph option
simpkins authored May 4, 2008
532 if (opt->use_terminator) {
533 if (!opt->missing_newline)
534 graph_show_padding(opt->graph);
9b58bfe @simpkins log: print log entry terminator even if the message is empty
simpkins authored Apr 29, 2008
535 putchar('\n');
7fefda5 @simpkins log and rev-list: add --graph option
simpkins authored May 4, 2008
536 }
537
674d172 Rework pretty_print_commit to use strbufs instead of custom buffers.
Pierre Habouzit authored Sep 10, 2007
538 strbuf_release(&msgbuf);
9153983 Log message printout cleanups
Linus Torvalds authored Apr 17, 2006
539 }
540
cd2bdc5 Common option parsing for "git log --diff" and friends
Linus Torvalds authored Apr 14, 2006
541 int log_tree_diff_flush(struct rev_info *opt)
5f1c3f0 log-tree: separate major part of diff-tree.
Junio C Hamano authored Apr 9, 2006
542 {
543 diffcore_std(&opt->diffopt);
9153983 Log message printout cleanups
Linus Torvalds authored Apr 17, 2006
544
5f1c3f0 log-tree: separate major part of diff-tree.
Junio C Hamano authored Apr 9, 2006
545 if (diff_queue_is_empty()) {
546 int saved_fmt = opt->diffopt.output_format;
547 opt->diffopt.output_format = DIFF_FORMAT_NO_OUTPUT;
548 diff_flush(&opt->diffopt);
549 opt->diffopt.output_format = saved_fmt;
550 return 0;
551 }
9153983 Log message printout cleanups
Linus Torvalds authored Apr 17, 2006
552
3969cf7 Fix some more diff options changes.
Junio C Hamano authored Jun 27, 2006
553 if (opt->loginfo && !opt->no_commit_id) {
554 /* When showing a verbose header (i.e. log message),
555 * and not in --pretty=oneline format, we would want
556 * an extra newline between the end of log and the
557 * output for readability.
558 */
0286565 @simpkins Remove dead code: show_log() sep argument and diff_options.msg_sep
simpkins authored Apr 29, 2008
559 show_log(opt);
304b5af @torvalds Clean up "git log" format with DIFF_FORMAT_NO_OUTPUT
torvalds authored Oct 9, 2007
560 if ((opt->diffopt.output_format & ~DIFF_FORMAT_NO_OUTPUT) &&
561 opt->verbose_header &&
3969cf7 Fix some more diff options changes.
Junio C Hamano authored Jun 27, 2006
562 opt->commit_format != CMIT_FMT_ONELINE) {
563 int pch = DIFF_FORMAT_DIFFSTAT | DIFF_FORMAT_PATCH;
564 if ((pch & opt->diffopt.output_format) == pch)
abd4e22 @torvalds Fix "git log -z" behaviour
torvalds authored Feb 7, 2007
565 printf("---");
81bd1b2 @byang Output the graph columns at the end of the commit message
byang authored May 26, 2010
566 if (opt->diffopt.output_prefix) {
567 struct strbuf *msg = NULL;
568 msg = opt->diffopt.output_prefix(&opt->diffopt,
569 opt->diffopt.output_prefix_data);
570 fwrite(msg->buf, msg->len, 1, stdout);
571 }
abd4e22 @torvalds Fix "git log -z" behaviour
torvalds authored Feb 7, 2007
572 putchar('\n');
3969cf7 Fix some more diff options changes.
Junio C Hamano authored Jun 27, 2006
573 }
574 }
5f1c3f0 log-tree: separate major part of diff-tree.
Junio C Hamano authored Apr 9, 2006
575 diff_flush(&opt->diffopt);
576 return 1;
577 }
578
cd2bdc5 Common option parsing for "git log --diff" and friends
Linus Torvalds authored Apr 14, 2006
579 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 Apr 9, 2006
580 {
581 unsigned const char *sha1 = commit->object.sha1;
582
9153983 Log message printout cleanups
Linus Torvalds authored Apr 17, 2006
583 diff_tree_combined_merge(sha1, opt->dense_combined_merges, opt);
584 return !opt->loginfo;
5f1c3f0 log-tree: separate major part of diff-tree.
Junio C Hamano authored Apr 9, 2006
585 }
586
9153983 Log message printout cleanups
Linus Torvalds authored Apr 17, 2006
587 /*
588 * Show the diff of a commit.
589 *
590 * Return true if we printed any log info messages
591 */
592 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 Apr 9, 2006
593 {
9153983 Log message printout cleanups
Linus Torvalds authored Apr 17, 2006
594 int showed_log;
5f1c3f0 log-tree: separate major part of diff-tree.
Junio C Hamano authored Apr 9, 2006
595 struct commit_list *parents;
596 unsigned const char *sha1 = commit->object.sha1;
597
84102a3 @pmorch Teach git log --exit-code to return an appropriate exit code
pmorch authored Aug 11, 2008
598 if (!opt->diff && !DIFF_OPT_TST(&opt->diffopt, EXIT_WITH_STATUS))
9153983 Log message printout cleanups
Linus Torvalds authored Apr 17, 2006
599 return 0;
600
5f1c3f0 log-tree: separate major part of diff-tree.
Junio C Hamano authored Apr 9, 2006
601 /* Root commit? */
9153983 Log message printout cleanups
Linus Torvalds authored Apr 17, 2006
602 parents = commit->parents;
603 if (!parents) {
2b60356 Make git-cherry handle root trees
Rene Scharfe authored Oct 26, 2006
604 if (opt->show_root_diff) {
605 diff_root_tree_sha1(sha1, "", &opt->diffopt);
606 log_tree_diff_flush(opt);
607 }
9153983 Log message printout cleanups
Linus Torvalds authored Apr 17, 2006
608 return !opt->loginfo;
5f1c3f0 log-tree: separate major part of diff-tree.
Junio C Hamano authored Apr 9, 2006
609 }
610
611 /* More than one parent? */
9153983 Log message printout cleanups
Linus Torvalds authored Apr 17, 2006
612 if (parents && parents->next) {
5f1c3f0 log-tree: separate major part of diff-tree.
Junio C Hamano authored Apr 9, 2006
613 if (opt->ignore_merges)
614 return 0;
615 else if (opt->combine_merges)
616 return do_diff_combined(opt, commit);
88d9d45 git log -p -m: document -m and honor --first-parent
Petr Baudis authored Feb 10, 2010
617 else if (opt->first_parent_only) {
618 /*
619 * Generate merge log entry only for the first
620 * parent, showing summary diff of the others
621 * we merged _in_.
622 */
623 diff_tree_sha1(parents->item->object.sha1, sha1, "", &opt->diffopt);
624 log_tree_diff_flush(opt);
625 return !opt->loginfo;
626 }
9153983 Log message printout cleanups
Linus Torvalds authored Apr 17, 2006
627
628 /* If we show individual diffs, show the parent info */
629 log->parent = parents->item;
5f1c3f0 log-tree: separate major part of diff-tree.
Junio C Hamano authored Apr 9, 2006
630 }
631
9153983 Log message printout cleanups
Linus Torvalds authored Apr 17, 2006
632 showed_log = 0;
633 for (;;) {
5f1c3f0 log-tree: separate major part of diff-tree.
Junio C Hamano authored Apr 9, 2006
634 struct commit *parent = parents->item;
635
9153983 Log message printout cleanups
Linus Torvalds authored Apr 17, 2006
636 diff_tree_sha1(parent->object.sha1, sha1, "", &opt->diffopt);
637 log_tree_diff_flush(opt);
638
639 showed_log |= !opt->loginfo;
640
641 /* Set up the log info for the next parent, if any.. */
642 parents = parents->next;
643 if (!parents)
644 break;
645 log->parent = parents->item;
646 opt->loginfo = log;
647 }
648 return showed_log;
649 }
650
651 int log_tree_commit(struct rev_info *opt, struct commit *commit)
652 {
653 struct log_info log;
3eefc18 Tentative built-in format-patch.
Junio C Hamano authored Apr 18, 2006
654 int shown;
9153983 Log message printout cleanups
Linus Torvalds authored Apr 17, 2006
655
656 log.commit = commit;
657 log.parent = NULL;
658 opt->loginfo = &log;
659
3eefc18 Tentative built-in format-patch.
Junio C Hamano authored Apr 18, 2006
660 shown = log_tree_diff(opt, commit, &log);
661 if (!shown && opt->loginfo && opt->always_show_header) {
9153983 Log message printout cleanups
Linus Torvalds authored Apr 17, 2006
662 log.parent = NULL;
0286565 @simpkins Remove dead code: show_log() sep argument and diff_options.msg_sep
simpkins authored Apr 29, 2008
663 show_log(opt);
3eefc18 Tentative built-in format-patch.
Junio C Hamano authored Apr 18, 2006
664 shown = 1;
5f1c3f0 log-tree: separate major part of diff-tree.
Junio C Hamano authored Apr 9, 2006
665 }
9153983 Log message printout cleanups
Linus Torvalds authored Apr 17, 2006
666 opt->loginfo = NULL;
06f59e9 @tytso Don't fflush(stdout) when it's not helpful
tytso authored Jun 29, 2007
667 maybe_flush_or_die(stdout, "stdout");
3eefc18 Tentative built-in format-patch.
Junio C Hamano authored Apr 18, 2006
668 return shown;
5f1c3f0 log-tree: separate major part of diff-tree.
Junio C Hamano authored Apr 9, 2006
669 }
Something went wrong with that request. Please try again.