add -C[NUM] to git-am
[git/git.git] / builtin-log.c
CommitLineData
70827b15
LT
1/*
2 * Builtin "git log" and related commands (show, whatchanged)
3 *
4 * (C) Copyright 2006 Linus Torvalds
5 * 2006 Junio Hamano
6 */
7#include "cache.h"
8#include "commit.h"
9#include "diff.h"
10#include "revision.h"
11#include "log-tree.h"
91efcf60 12#include "builtin.h"
5d7eeee2 13#include "tag.h"
70827b15 14
0f03ca94
PB
15static int default_show_root = 1;
16
e686eb98
JS
17/* this is in builtin-diff.c */
18void add_head(struct rev_info *revs);
19
a633fca0 20static void cmd_log_init(int argc, const char **argv, const char *prefix,
70827b15
LT
21 struct rev_info *rev)
22{
52883fbd
JH
23 int i;
24
70827b15
LT
25 rev->abbrev = DEFAULT_ABBREV;
26 rev->commit_format = CMIT_FMT_DEFAULT;
27 rev->verbose_header = 1;
0f03ca94 28 rev->show_root_diff = default_show_root;
70827b15 29 argc = setup_revisions(argc, argv, rev, "HEAD");
9dafea26
TH
30 if (rev->diffopt.pickaxe || rev->diffopt.filter)
31 rev->always_show_header = 0;
52883fbd
JH
32 for (i = 1; i < argc; i++) {
33 const char *arg = argv[i];
34 if (!strncmp(arg, "--encoding=", 11)) {
35 arg += 11;
52883fbd 36 if (strcmp(arg, "none"))
d2c11a38 37 git_log_output_encoding = strdup(arg);
52883fbd 38 else
d2c11a38 39 git_log_output_encoding = "";
52883fbd
JH
40 }
41 else
42 die("unrecognized argument: %s", arg);
43 }
9dafea26
TH
44}
45
46static int cmd_log_walk(struct rev_info *rev)
47{
48 struct commit *commit;
70827b15
LT
49
50 prepare_revision_walk(rev);
70827b15
LT
51 while ((commit = get_revision(rev)) != NULL) {
52 log_tree_commit(rev, commit);
a6c73064
JS
53 if (!rev->reflog_info) {
54 /* we allow cycles in reflog ancestry */
55 free(commit->buffer);
56 commit->buffer = NULL;
57 }
cb115748
LT
58 free_commit_list(commit->parents);
59 commit->parents = NULL;
70827b15
LT
60 }
61 return 0;
62}
63
0f03ca94
PB
64static int git_log_config(const char *var, const char *value)
65{
66 if (!strcmp(var, "log.showroot")) {
67 default_show_root = git_config_bool(var, value);
68 return 0;
69 }
70 return git_diff_ui_config(var, value);
71}
72
a633fca0 73int cmd_whatchanged(int argc, const char **argv, const char *prefix)
70827b15
LT
74{
75 struct rev_info rev;
76
0f03ca94 77 git_config(git_log_config);
db6296a5 78 init_revisions(&rev, prefix);
70827b15
LT
79 rev.diff = 1;
80 rev.diffopt.recursive = 1;
9202434c 81 rev.simplify_history = 0;
a633fca0 82 cmd_log_init(argc, argv, prefix, &rev);
9dafea26
TH
83 if (!rev.diffopt.output_format)
84 rev.diffopt.output_format = DIFF_FORMAT_RAW;
85 return cmd_log_walk(&rev);
70827b15
LT
86}
87
5d7eeee2
JS
88static int show_object(const unsigned char *sha1, int suppress_header)
89{
90 unsigned long size;
91 char type[20];
92 char *buf = read_sha1_file(sha1, type, &size);
93 int offset = 0;
94
95 if (!buf)
96 return error("Could not read object %s", sha1_to_hex(sha1));
97
98 if (suppress_header)
99 while (offset < size && buf[offset++] != '\n') {
100 int new_offset = offset;
101 while (new_offset < size && buf[new_offset++] != '\n')
102 ; /* do nothing */
103 offset = new_offset;
104 }
105
106 if (offset < size)
107 fwrite(buf + offset, size - offset, 1, stdout);
108 free(buf);
109 return 0;
110}
111
112static int show_tree_object(const unsigned char *sha1,
113 const char *base, int baselen,
114 const char *pathname, unsigned mode, int stage)
115{
116 printf("%s%s\n", pathname, S_ISDIR(mode) ? "/" : "");
117 return 0;
118}
119
a633fca0 120int cmd_show(int argc, const char **argv, const char *prefix)
70827b15
LT
121{
122 struct rev_info rev;
5d7eeee2
JS
123 struct object_array_entry *objects;
124 int i, count, ret = 0;
70827b15 125
0f03ca94 126 git_config(git_log_config);
db6296a5 127 init_revisions(&rev, prefix);
70827b15
LT
128 rev.diff = 1;
129 rev.diffopt.recursive = 1;
130 rev.combine_merges = 1;
131 rev.dense_combined_merges = 1;
132 rev.always_show_header = 1;
133 rev.ignore_merges = 0;
134 rev.no_walk = 1;
a633fca0 135 cmd_log_init(argc, argv, prefix, &rev);
5d7eeee2
JS
136
137 count = rev.pending.nr;
138 objects = rev.pending.objects;
139 for (i = 0; i < count && !ret; i++) {
140 struct object *o = objects[i].item;
141 const char *name = objects[i].name;
142 switch (o->type) {
143 case OBJ_BLOB:
144 ret = show_object(o->sha1, 0);
145 break;
146 case OBJ_TAG: {
147 struct tag *t = (struct tag *)o;
148
149 printf("%stag %s%s\n\n",
150 diff_get_color(rev.diffopt.color_diff,
151 DIFF_COMMIT),
152 t->tag,
153 diff_get_color(rev.diffopt.color_diff,
154 DIFF_RESET));
155 ret = show_object(o->sha1, 1);
156 objects[i].item = (struct object *)t->tagged;
157 i--;
158 break;
159 }
160 case OBJ_TREE:
161 printf("%stree %s%s\n\n",
162 diff_get_color(rev.diffopt.color_diff,
163 DIFF_COMMIT),
164 name,
165 diff_get_color(rev.diffopt.color_diff,
166 DIFF_RESET));
167 read_tree_recursive((struct tree *)o, "", 0, 0, NULL,
168 show_tree_object);
169 break;
170 case OBJ_COMMIT:
171 rev.pending.nr = rev.pending.alloc = 0;
172 rev.pending.objects = NULL;
173 add_object_array(o, name, &rev.pending);
174 ret = cmd_log_walk(&rev);
175 break;
176 default:
177 ret = error("Unknown type: %d", o->type);
178 }
179 }
180 free(objects);
181 return ret;
70827b15
LT
182}
183
a633fca0 184int cmd_log(int argc, const char **argv, const char *prefix)
70827b15
LT
185{
186 struct rev_info rev;
187
0f03ca94 188 git_config(git_log_config);
db6296a5 189 init_revisions(&rev, prefix);
70827b15 190 rev.always_show_header = 1;
a633fca0 191 cmd_log_init(argc, argv, prefix, &rev);
9dafea26 192 return cmd_log_walk(&rev);
70827b15 193}
91efcf60 194
0377db77
JS
195static int istitlechar(char c)
196{
197 return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') ||
198 (c >= '0' && c <= '9') || c == '.' || c == '_';
199}
200
20ff0680
JS
201static char *extra_headers = NULL;
202static int extra_headers_size = 0;
917a8f89 203static const char *fmt_patch_suffix = ".patch";
20ff0680
JS
204
205static int git_format_config(const char *var, const char *value)
206{
207 if (!strcmp(var, "format.headers")) {
d7fb91c6
JH
208 int len;
209
210 if (!value)
211 die("format.headers without value");
212 len = strlen(value);
20ff0680 213 extra_headers_size += len + 1;
83572c1a 214 extra_headers = xrealloc(extra_headers, extra_headers_size);
20ff0680
JS
215 extra_headers[extra_headers_size - len - 1] = 0;
216 strcat(extra_headers, value);
217 return 0;
218 }
03eeaeae
JH
219 if (!strcmp(var, "format.suffix")) {
220 if (!value)
221 die("format.suffix without value");
222 fmt_patch_suffix = xstrdup(value);
223 return 0;
224 }
a159ca0c 225 if (!strcmp(var, "diff.color") || !strcmp(var, "color.diff")) {
f3aafa4d
RA
226 return 0;
227 }
0f03ca94 228 return git_log_config(var, value);
20ff0680
JS
229}
230
231
81f3a188 232static FILE *realstdout = NULL;
efd02016 233static const char *output_directory = NULL;
81f3a188 234
8ac80a57 235static void reopen_stdout(struct commit *commit, int nr, int keep_subject)
0377db77
JS
236{
237 char filename[1024];
238 char *sol;
2448482b 239 int len = 0;
03eeaeae 240 int suffix_len = strlen(fmt_patch_suffix) + 10; /* ., NUL and slop */
0377db77 241
2448482b 242 if (output_directory) {
03eeaeae 243 strlcpy(filename, output_directory, 1000);
2448482b
JS
244 len = strlen(filename);
245 if (filename[len - 1] != '/')
246 filename[len++] = '/';
247 }
0377db77 248
2448482b 249 sprintf(filename + len, "%04d", nr);
0377db77
JS
250 len = strlen(filename);
251
252 sol = strstr(commit->buffer, "\n\n");
253 if (sol) {
254 int j, space = 1;
255
256 sol += 2;
257 /* strip [PATCH] or [PATCH blabla] */
8ac80a57 258 if (!keep_subject && !strncmp(sol, "[PATCH", 6)) {
0377db77
JS
259 char *eos = strchr(sol + 6, ']');
260 if (eos) {
261 while (isspace(*eos))
262 eos++;
263 sol = eos;
264 }
265 }
266
03eeaeae
JH
267 for (j = 0;
268 len < sizeof(filename) - suffix_len &&
269 sol[j] && sol[j] != '\n';
270 j++) {
0377db77
JS
271 if (istitlechar(sol[j])) {
272 if (space) {
273 filename[len++] = '-';
274 space = 0;
275 }
276 filename[len++] = sol[j];
277 if (sol[j] == '.')
278 while (sol[j + 1] == '.')
279 j++;
280 } else
281 space = 1;
282 }
283 while (filename[len - 1] == '.' || filename[len - 1] == '-')
284 len--;
285 }
03eeaeae 286 strcpy(filename + len, fmt_patch_suffix);
81f3a188 287 fprintf(realstdout, "%s\n", filename);
0377db77
JS
288 freopen(filename, "w", stdout);
289}
290
9c6efa36
JS
291static int get_patch_id(struct commit *commit, struct diff_options *options,
292 unsigned char *sha1)
293{
2b60356d
RS
294 if (commit->parents)
295 diff_tree_sha1(commit->parents->item->object.sha1,
296 commit->object.sha1, "", options);
297 else
298 diff_root_tree_sha1(commit->object.sha1, "", options);
9c6efa36
JS
299 diffcore_std(options);
300 return diff_flush_patch_id(options, sha1);
301}
302
a633fca0 303static void get_patch_ids(struct rev_info *rev, struct diff_options *options, const char *prefix)
9c6efa36
JS
304{
305 struct rev_info check_rev;
306 struct commit *commit;
307 struct object *o1, *o2;
308 unsigned flags1, flags2;
309 unsigned char sha1[20];
310
311 if (rev->pending.nr != 2)
312 die("Need exactly one range.");
313
314 o1 = rev->pending.objects[0].item;
315 flags1 = o1->flags;
316 o2 = rev->pending.objects[1].item;
317 flags2 = o2->flags;
318
319 if ((flags1 & UNINTERESTING) == (flags2 & UNINTERESTING))
320 die("Not a range.");
321
322 diff_setup(options);
323 options->recursive = 1;
324 if (diff_setup_done(options) < 0)
325 die("diff_setup_done failed");
326
327 /* given a range a..b get all patch ids for b..a */
db6296a5 328 init_revisions(&check_rev, prefix);
9c6efa36
JS
329 o1->flags ^= UNINTERESTING;
330 o2->flags ^= UNINTERESTING;
331 add_pending_object(&check_rev, o1, "o1");
332 add_pending_object(&check_rev, o2, "o2");
333 prepare_revision_walk(&check_rev);
334
335 while ((commit = get_revision(&check_rev)) != NULL) {
336 /* ignore merges */
337 if (commit->parents && commit->parents->next)
338 continue;
339
340 if (!get_patch_id(commit, options, sha1))
341 created_object(sha1, xcalloc(1, sizeof(struct object)));
342 }
343
344 /* reset for next revision walk */
81db0941
JS
345 clear_commit_marks((struct commit *)o1,
346 SEEN | UNINTERESTING | SHOWN | ADDED);
347 clear_commit_marks((struct commit *)o2,
348 SEEN | UNINTERESTING | SHOWN | ADDED);
9c6efa36
JS
349 o1->flags = flags1;
350 o2->flags = flags2;
351}
352
d1566f78
JT
353static void gen_message_id(char *dest, unsigned int length, char *base)
354{
cb280e10 355 const char *committer = git_committer_info(-1);
d1566f78
JT
356 const char *email_start = strrchr(committer, '<');
357 const char *email_end = strrchr(committer, '>');
358 if(!email_start || !email_end || email_start > email_end - 1)
359 die("Could not extract email from committer identity.");
76af0734
JH
360 snprintf(dest, length, "%s.%lu.git.%.*s", base,
361 (unsigned long) time(NULL),
362 (int)(email_end - email_start - 1), email_start + 1);
d1566f78
JT
363}
364
a633fca0 365int cmd_format_patch(int argc, const char **argv, const char *prefix)
91efcf60
JH
366{
367 struct commit *commit;
368 struct commit **list = NULL;
369 struct rev_info rev;
2448482b 370 int nr = 0, total, i, j;
0377db77 371 int use_stdout = 0;
596524b3 372 int numbered = 0;
fa0f02df 373 int start_number = -1;
8ac80a57 374 int keep_subject = 0;
9c6efa36 375 int ignore_if_in_upstream = 0;
cc35de84 376 int thread = 0;
76af0734 377 const char *in_reply_to = NULL;
9c6efa36 378 struct diff_options patch_id_opts;
cf2251b6 379 char *add_signoff = NULL;
d1566f78
JT
380 char message_id[1024];
381 char ref_message_id[1024];
91efcf60 382
97beb812 383 git_config(git_format_config);
db6296a5 384 init_revisions(&rev, prefix);
91efcf60
JH
385 rev.commit_format = CMIT_FMT_EMAIL;
386 rev.verbose_header = 1;
387 rev.diff = 1;
91efcf60
JH
388 rev.combine_merges = 0;
389 rev.ignore_merges = 1;
27e1b127
JH
390 rev.diffopt.msg_sep = "";
391 rev.diffopt.recursive = 1;
91efcf60 392
20ff0680
JS
393 rev.extra_headers = extra_headers;
394
2448482b
JS
395 /*
396 * Parse the arguments before setup_revisions(), or something
397 * like "git fmt-patch -o a123 HEAD^.." may fail; a123 is
398 * possibly a valid SHA1.
399 */
400 for (i = 1, j = 1; i < argc; i++) {
401 if (!strcmp(argv[i], "--stdout"))
0377db77 402 use_stdout = 1;
596524b3
JS
403 else if (!strcmp(argv[i], "-n") ||
404 !strcmp(argv[i], "--numbered"))
405 numbered = 1;
fa0f02df
JS
406 else if (!strncmp(argv[i], "--start-number=", 15))
407 start_number = strtol(argv[i] + 15, NULL, 10);
408 else if (!strcmp(argv[i], "--start-number")) {
409 i++;
410 if (i == argc)
411 die("Need a number for --start-number");
412 start_number = strtol(argv[i], NULL, 10);
cf2251b6
JH
413 }
414 else if (!strcmp(argv[i], "-k") ||
8ac80a57
JS
415 !strcmp(argv[i], "--keep-subject")) {
416 keep_subject = 1;
417 rev.total = -1;
cf2251b6 418 }
efd02016
JH
419 else if (!strcmp(argv[i], "--output-directory") ||
420 !strcmp(argv[i], "-o")) {
2448482b 421 i++;
efd02016
JH
422 if (argc <= i)
423 die("Which directory?");
424 if (output_directory)
425 die("Two output directories?");
426 output_directory = argv[i];
698ce6f8 427 }
cf2251b6
JH
428 else if (!strcmp(argv[i], "--signoff") ||
429 !strcmp(argv[i], "-s")) {
6c4cca1c
EB
430 const char *committer;
431 const char *endpos;
6c4cca1c
EB
432 committer = git_committer_info(1);
433 endpos = strchr(committer, '>');
cf2251b6
JH
434 if (!endpos)
435 die("bogos committer info %s\n", committer);
436 add_signoff = xmalloc(endpos - committer + 2);
437 memcpy(add_signoff, committer, endpos - committer + 1);
438 add_signoff[endpos - committer + 1] = 0;
439 }
698ce6f8
JS
440 else if (!strcmp(argv[i], "--attach"))
441 rev.mime_boundary = git_version_string;
442 else if (!strncmp(argv[i], "--attach=", 9))
443 rev.mime_boundary = argv[i] + 9;
9c6efa36
JS
444 else if (!strcmp(argv[i], "--ignore-if-in-upstream"))
445 ignore_if_in_upstream = 1;
cc35de84
JT
446 else if (!strcmp(argv[i], "--thread"))
447 thread = 1;
da56645d
JT
448 else if (!strncmp(argv[i], "--in-reply-to=", 14))
449 in_reply_to = argv[i] + 14;
450 else if (!strcmp(argv[i], "--in-reply-to")) {
451 i++;
452 if (i == argc)
453 die("Need a Message-Id for --in-reply-to");
454 in_reply_to = argv[i];
455 }
03eeaeae
JH
456 else if (!strncmp(argv[i], "--suffix=", 9))
457 fmt_patch_suffix = argv[i] + 9;
698ce6f8 458 else
2448482b 459 argv[j++] = argv[i];
0377db77 460 }
2448482b
JS
461 argc = j;
462
add5c8a5 463 if (start_number < 0)
fa0f02df 464 start_number = 1;
63b398a4 465 if (numbered && keep_subject)
8ac80a57
JS
466 die ("-n and -k are mutually exclusive.");
467
2448482b
JS
468 argc = setup_revisions(argc, argv, &rev, "HEAD");
469 if (argc > 1)
470 die ("unrecognized argument: %s", argv[1]);
0377db77 471
c9b5ef99 472 if (!rev.diffopt.output_format)
c261e438 473 rev.diffopt.output_format = DIFF_FORMAT_DIFFSTAT | DIFF_FORMAT_SUMMARY | DIFF_FORMAT_PATCH;
c9b5ef99 474
e47f306d
JH
475 if (!rev.diffopt.text)
476 rev.diffopt.binary = 1;
477
90f70a91 478 if (!output_directory && !use_stdout)
77e565d8
ML
479 output_directory = prefix;
480
efd02016
JH
481 if (output_directory) {
482 if (use_stdout)
483 die("standard output, or directory, which one?");
484 if (mkdir(output_directory, 0777) < 0 && errno != EEXIST)
485 die("Could not create directory %s",
486 output_directory);
487 }
488
1f1e895f 489 if (rev.pending.nr == 1) {
7c496280
JH
490 if (rev.max_count < 0) {
491 rev.pending.objects[0].item->flags |= UNINTERESTING;
492 add_head(&rev);
493 }
494 /* Otherwise, it is "format-patch -22 HEAD", and
495 * get_revision() would return only the specified count.
496 */
e686eb98
JS
497 }
498
9c6efa36 499 if (ignore_if_in_upstream)
a633fca0 500 get_patch_ids(&rev, &patch_id_opts, prefix);
9c6efa36 501
81f3a188
JS
502 if (!use_stdout)
503 realstdout = fdopen(dup(1), "w");
504
91efcf60
JH
505 prepare_revision_walk(&rev);
506 while ((commit = get_revision(&rev)) != NULL) {
9c6efa36
JS
507 unsigned char sha1[20];
508
0377db77
JS
509 /* ignore merges */
510 if (commit->parents && commit->parents->next)
511 continue;
9c6efa36
JS
512
513 if (ignore_if_in_upstream &&
514 !get_patch_id(commit, &patch_id_opts, sha1) &&
515 lookup_object(sha1))
516 continue;
517
91efcf60 518 nr++;
83572c1a 519 list = xrealloc(list, nr * sizeof(list[0]));
91efcf60
JH
520 list[nr - 1] = commit;
521 }
0377db77 522 total = nr;
596524b3 523 if (numbered)
fa0f02df 524 rev.total = total + start_number - 1;
cf2251b6 525 rev.add_signoff = add_signoff;
da56645d 526 rev.ref_message_id = in_reply_to;
91efcf60
JH
527 while (0 <= --nr) {
528 int shown;
529 commit = list[nr];
add5c8a5 530 rev.nr = total - nr + (start_number - 1);
d1566f78 531 /* Make the second and subsequent mails replies to the first */
cc35de84
JT
532 if (thread) {
533 if (nr == (total - 2)) {
534 strncpy(ref_message_id, message_id,
535 sizeof(ref_message_id));
536 ref_message_id[sizeof(ref_message_id)-1]='\0';
537 rev.ref_message_id = ref_message_id;
538 }
539 gen_message_id(message_id, sizeof(message_id),
540 sha1_to_hex(commit->object.sha1));
541 rev.message_id = message_id;
d1566f78 542 }
0377db77 543 if (!use_stdout)
8ac80a57 544 reopen_stdout(commit, rev.nr, keep_subject);
91efcf60
JH
545 shown = log_tree_commit(&rev, commit);
546 free(commit->buffer);
547 commit->buffer = NULL;
add5c8a5
JH
548
549 /* We put one extra blank line between formatted
550 * patches and this flag is used by log-tree code
551 * to see if it needs to emit a LF before showing
552 * the log; when using one file per patch, we do
553 * not want the extra blank line.
554 */
555 if (!use_stdout)
556 rev.shown_one = 0;
698ce6f8
JS
557 if (shown) {
558 if (rev.mime_boundary)
559 printf("\n--%s%s--\n\n\n",
560 mime_boundary_leader,
561 rev.mime_boundary);
562 else
563 printf("-- \n%s\n\n", git_version_string);
564 }
0377db77
JS
565 if (!use_stdout)
566 fclose(stdout);
91efcf60
JH
567 }
568 free(list);
569 return 0;
570}
571
e827633a
RS
572static int add_pending_commit(const char *arg, struct rev_info *revs, int flags)
573{
574 unsigned char sha1[20];
575 if (get_sha1(arg, sha1) == 0) {
576 struct commit *commit = lookup_commit_reference(sha1);
577 if (commit) {
578 commit->object.flags |= flags;
579 add_pending_object(revs, &commit->object, arg);
580 return 0;
581 }
582 }
583 return -1;
584}
585
586static const char cherry_usage[] =
587"git-cherry [-v] <upstream> [<head>] [<limit>]";
588int cmd_cherry(int argc, const char **argv, const char *prefix)
589{
590 struct rev_info revs;
591 struct diff_options patch_id_opts;
592 struct commit *commit;
593 struct commit_list *list = NULL;
594 const char *upstream;
595 const char *head = "HEAD";
596 const char *limit = NULL;
597 int verbose = 0;
598
599 if (argc > 1 && !strcmp(argv[1], "-v")) {
600 verbose = 1;
601 argc--;
602 argv++;
603 }
604
605 switch (argc) {
606 case 4:
607 limit = argv[3];
608 /* FALLTHROUGH */
609 case 3:
610 head = argv[2];
611 /* FALLTHROUGH */
612 case 2:
613 upstream = argv[1];
614 break;
615 default:
616 usage(cherry_usage);
617 }
618
619 init_revisions(&revs, prefix);
620 revs.diff = 1;
621 revs.combine_merges = 0;
622 revs.ignore_merges = 1;
623 revs.diffopt.recursive = 1;
624
625 if (add_pending_commit(head, &revs, 0))
626 die("Unknown commit %s", head);
627 if (add_pending_commit(upstream, &revs, UNINTERESTING))
628 die("Unknown commit %s", upstream);
629
630 /* Don't say anything if head and upstream are the same. */
631 if (revs.pending.nr == 2) {
632 struct object_array_entry *o = revs.pending.objects;
633 if (hashcmp(o[0].item->sha1, o[1].item->sha1) == 0)
634 return 0;
635 }
636
637 get_patch_ids(&revs, &patch_id_opts, prefix);
638
639 if (limit && add_pending_commit(limit, &revs, UNINTERESTING))
640 die("Unknown commit %s", limit);
641
642 /* reverse the list of commits */
643 prepare_revision_walk(&revs);
644 while ((commit = get_revision(&revs)) != NULL) {
645 /* ignore merges */
646 if (commit->parents && commit->parents->next)
647 continue;
648
649 commit_list_insert(commit, &list);
650 }
651
652 while (list) {
653 unsigned char sha1[20];
654 char sign = '+';
655
656 commit = list->item;
657 if (!get_patch_id(commit, &patch_id_opts, sha1) &&
658 lookup_object(sha1))
659 sign = '-';
660
661 if (verbose) {
662 static char buf[16384];
663 pretty_print_commit(CMIT_FMT_ONELINE, commit, ~0,
664 buf, sizeof(buf), 0, NULL, NULL, 0);
665 printf("%c %s %s\n", sign,
666 sha1_to_hex(commit->object.sha1), buf);
667 }
668 else {
669 printf("%c %s\n", sign,
670 sha1_to_hex(commit->object.sha1));
671 }
672
673 list = list->next;
674 }
675
676 return 0;
677}