builtin-log.c 17.5 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11
/*
 * Builtin "git log" and related commands (show, whatchanged)
 *
 * (C) Copyright 2006 Linus Torvalds
 *		 2006 Junio Hamano
 */
#include "cache.h"
#include "commit.h"
#include "diff.h"
#include "revision.h"
#include "log-tree.h"
12
#include "builtin.h"
13
#include "tag.h"
L
Linus Torvalds 已提交
14
#include "reflog-walk.h"
15

16 17
static int default_show_root = 1;

18 19 20
/* this is in builtin-diff.c */
void add_head(struct rev_info *revs);

21
static void cmd_log_init(int argc, const char **argv, const char *prefix,
22 23
		      struct rev_info *rev)
{
J
Junio C Hamano 已提交
24 25
	int i;

26 27 28
	rev->abbrev = DEFAULT_ABBREV;
	rev->commit_format = CMIT_FMT_DEFAULT;
	rev->verbose_header = 1;
29
	rev->show_root_diff = default_show_root;
30
	argc = setup_revisions(argc, argv, rev, "HEAD");
31 32
	if (rev->diffopt.pickaxe || rev->diffopt.filter)
		rev->always_show_header = 0;
J
Junio C Hamano 已提交
33 34 35 36 37
	for (i = 1; i < argc; i++) {
		const char *arg = argv[i];
		if (!strncmp(arg, "--encoding=", 11)) {
			arg += 11;
			if (strcmp(arg, "none"))
38
				git_log_output_encoding = strdup(arg);
J
Junio C Hamano 已提交
39
			else
40
				git_log_output_encoding = "";
J
Junio C Hamano 已提交
41 42 43 44
		}
		else
			die("unrecognized argument: %s", arg);
	}
45 46 47 48 49
}

static int cmd_log_walk(struct rev_info *rev)
{
	struct commit *commit;
50 51 52 53

	prepare_revision_walk(rev);
	while ((commit = get_revision(rev)) != NULL) {
		log_tree_commit(rev, commit);
54 55 56 57 58
		if (!rev->reflog_info) {
			/* we allow cycles in reflog ancestry */
			free(commit->buffer);
			commit->buffer = NULL;
		}
L
Linus Torvalds 已提交
59 60
		free_commit_list(commit->parents);
		commit->parents = NULL;
61 62 63 64
	}
	return 0;
}

65 66 67 68 69 70 71 72 73
static int git_log_config(const char *var, const char *value)
{
	if (!strcmp(var, "log.showroot")) {
		default_show_root = git_config_bool(var, value);
		return 0;
	}
	return git_diff_ui_config(var, value);
}

74
int cmd_whatchanged(int argc, const char **argv, const char *prefix)
75 76 77
{
	struct rev_info rev;

78
	git_config(git_log_config);
79
	init_revisions(&rev, prefix);
80 81
	rev.diff = 1;
	rev.diffopt.recursive = 1;
L
Linus Torvalds 已提交
82
	rev.simplify_history = 0;
83
	cmd_log_init(argc, argv, prefix, &rev);
84 85 86
	if (!rev.diffopt.output_format)
		rev.diffopt.output_format = DIFF_FORMAT_RAW;
	return cmd_log_walk(&rev);
87 88
}

89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
static int show_object(const unsigned char *sha1, int suppress_header)
{
	unsigned long size;
	char type[20];
	char *buf = read_sha1_file(sha1, type, &size);
	int offset = 0;

	if (!buf)
		return error("Could not read object %s", sha1_to_hex(sha1));

	if (suppress_header)
		while (offset < size && buf[offset++] != '\n') {
			int new_offset = offset;
			while (new_offset < size && buf[new_offset++] != '\n')
				; /* do nothing */
			offset = new_offset;
		}

	if (offset < size)
		fwrite(buf + offset, size - offset, 1, stdout);
	free(buf);
	return 0;
}

static int show_tree_object(const unsigned char *sha1,
		const char *base, int baselen,
		const char *pathname, unsigned mode, int stage)
{
	printf("%s%s\n", pathname, S_ISDIR(mode) ? "/" : "");
	return 0;
}

121
int cmd_show(int argc, const char **argv, const char *prefix)
122 123
{
	struct rev_info rev;
124 125
	struct object_array_entry *objects;
	int i, count, ret = 0;
126

127
	git_config(git_log_config);
128
	init_revisions(&rev, prefix);
129 130 131 132 133 134 135
	rev.diff = 1;
	rev.diffopt.recursive = 1;
	rev.combine_merges = 1;
	rev.dense_combined_merges = 1;
	rev.always_show_header = 1;
	rev.ignore_merges = 0;
	rev.no_walk = 1;
136
	cmd_log_init(argc, argv, prefix, &rev);
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182

	count = rev.pending.nr;
	objects = rev.pending.objects;
	for (i = 0; i < count && !ret; i++) {
		struct object *o = objects[i].item;
		const char *name = objects[i].name;
		switch (o->type) {
		case OBJ_BLOB:
			ret = show_object(o->sha1, 0);
			break;
		case OBJ_TAG: {
			struct tag *t = (struct tag *)o;

			printf("%stag %s%s\n\n",
					diff_get_color(rev.diffopt.color_diff,
						DIFF_COMMIT),
					t->tag,
					diff_get_color(rev.diffopt.color_diff,
						DIFF_RESET));
			ret = show_object(o->sha1, 1);
			objects[i].item = (struct object *)t->tagged;
			i--;
			break;
		}
		case OBJ_TREE:
			printf("%stree %s%s\n\n",
					diff_get_color(rev.diffopt.color_diff,
						DIFF_COMMIT),
					name,
					diff_get_color(rev.diffopt.color_diff,
						DIFF_RESET));
			read_tree_recursive((struct tree *)o, "", 0, 0, NULL,
					show_tree_object);
			break;
		case OBJ_COMMIT:
			rev.pending.nr = rev.pending.alloc = 0;
			rev.pending.objects = NULL;
			add_object_array(o, name, &rev.pending);
			ret = cmd_log_walk(&rev);
			break;
		default:
			ret = error("Unknown type: %d", o->type);
		}
	}
	free(objects);
	return ret;
183 184
}

L
Linus Torvalds 已提交
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215
/*
 * This is equivalent to "git log -g --abbrev-commit --pretty=oneline"
 */
int cmd_log_reflog(int argc, const char **argv, const char *prefix)
{
	struct rev_info rev;

	git_config(git_log_config);
	init_revisions(&rev, prefix);
	init_reflog_walk(&rev.reflog_info);
	rev.abbrev_commit = 1;
	rev.verbose_header = 1;
	cmd_log_init(argc, argv, prefix, &rev);

	/*
	 * This means that we override whatever commit format the user gave
	 * on the cmd line.  Sad, but cmd_log_init() currently doesn't
	 * allow us to set a different default.
	 */
	rev.commit_format = CMIT_FMT_ONELINE;
	rev.always_show_header = 1;

	/*
	 * We get called through "git reflog", so unlike the other log
	 * routines, we need to set up our pager manually..
	 */
	setup_pager();

	return cmd_log_walk(&rev);
}

216
int cmd_log(int argc, const char **argv, const char *prefix)
217 218 219
{
	struct rev_info rev;

220
	git_config(git_log_config);
221
	init_revisions(&rev, prefix);
222
	rev.always_show_header = 1;
223
	cmd_log_init(argc, argv, prefix, &rev);
224
	return cmd_log_walk(&rev);
225
}
226

227 228 229 230 231 232
static int istitlechar(char c)
{
	return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') ||
		(c >= '0' && c <= '9') || c == '.' || c == '_';
}

233 234
static char *extra_headers = NULL;
static int extra_headers_size = 0;
235
static const char *fmt_patch_suffix = ".patch";
236 237 238 239

static int git_format_config(const char *var, const char *value)
{
	if (!strcmp(var, "format.headers")) {
240 241 242 243 244
		int len;

		if (!value)
			die("format.headers without value");
		len = strlen(value);
245
		extra_headers_size += len + 1;
J
Jonas Fonseca 已提交
246
		extra_headers = xrealloc(extra_headers, extra_headers_size);
247 248 249 250
		extra_headers[extra_headers_size - len - 1] = 0;
		strcat(extra_headers, value);
		return 0;
	}
251 252 253 254 255 256
	if (!strcmp(var, "format.suffix")) {
		if (!value)
			die("format.suffix without value");
		fmt_patch_suffix = xstrdup(value);
		return 0;
	}
257
	if (!strcmp(var, "diff.color") || !strcmp(var, "color.diff")) {
258 259
		return 0;
	}
260
	return git_log_config(var, value);
261 262 263
}


264
static FILE *realstdout = NULL;
265
static const char *output_directory = NULL;
266

267
static void reopen_stdout(struct commit *commit, int nr, int keep_subject)
268 269 270
{
	char filename[1024];
	char *sol;
271
	int len = 0;
272
	int suffix_len = strlen(fmt_patch_suffix) + 10; /* ., NUL and slop */
273

274
	if (output_directory) {
275
		strlcpy(filename, output_directory, 1000);
276 277 278 279
		len = strlen(filename);
		if (filename[len - 1] != '/')
			filename[len++] = '/';
	}
280

281
	sprintf(filename + len, "%04d", nr);
282 283 284 285 286 287 288 289
	len = strlen(filename);

	sol = strstr(commit->buffer, "\n\n");
	if (sol) {
		int j, space = 1;

		sol += 2;
		/* strip [PATCH] or [PATCH blabla] */
290
		if (!keep_subject && !strncmp(sol, "[PATCH", 6)) {
291 292 293 294 295 296 297 298
			char *eos = strchr(sol + 6, ']');
			if (eos) {
				while (isspace(*eos))
					eos++;
				sol = eos;
			}
		}

299 300 301 302
		for (j = 0;
		     len < sizeof(filename) - suffix_len &&
			     sol[j] && sol[j] != '\n';
		     j++) {
303 304 305 306 307 308 309 310 311 312 313 314 315 316 317
			if (istitlechar(sol[j])) {
				if (space) {
					filename[len++] = '-';
					space = 0;
				}
				filename[len++] = sol[j];
				if (sol[j] == '.')
					while (sol[j + 1] == '.')
						j++;
			} else
				space = 1;
		}
		while (filename[len - 1] == '.' || filename[len - 1] == '-')
			len--;
	}
318
	strcpy(filename + len, fmt_patch_suffix);
319
	fprintf(realstdout, "%s\n", filename);
320 321 322
	freopen(filename, "w", stdout);
}

323 324 325
static int get_patch_id(struct commit *commit, struct diff_options *options,
		unsigned char *sha1)
{
R
Rene Scharfe 已提交
326 327 328 329 330
	if (commit->parents)
		diff_tree_sha1(commit->parents->item->object.sha1,
		               commit->object.sha1, "", options);
	else
		diff_root_tree_sha1(commit->object.sha1, "", options);
331 332 333 334
	diffcore_std(options);
	return diff_flush_patch_id(options, sha1);
}

335
static void get_patch_ids(struct rev_info *rev, struct diff_options *options, const char *prefix)
336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359
{
	struct rev_info check_rev;
	struct commit *commit;
	struct object *o1, *o2;
	unsigned flags1, flags2;
	unsigned char sha1[20];

	if (rev->pending.nr != 2)
		die("Need exactly one range.");

	o1 = rev->pending.objects[0].item;
	flags1 = o1->flags;
	o2 = rev->pending.objects[1].item;
	flags2 = o2->flags;

	if ((flags1 & UNINTERESTING) == (flags2 & UNINTERESTING))
		die("Not a range.");

	diff_setup(options);
	options->recursive = 1;
	if (diff_setup_done(options) < 0)
		die("diff_setup_done failed");

	/* given a range a..b get all patch ids for b..a */
360
	init_revisions(&check_rev, prefix);
361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376
	o1->flags ^= UNINTERESTING;
	o2->flags ^= UNINTERESTING;
	add_pending_object(&check_rev, o1, "o1");
	add_pending_object(&check_rev, o2, "o2");
	prepare_revision_walk(&check_rev);

	while ((commit = get_revision(&check_rev)) != NULL) {
		/* ignore merges */
		if (commit->parents && commit->parents->next)
			continue;

		if (!get_patch_id(commit, options, sha1))
			created_object(sha1, xcalloc(1, sizeof(struct object)));
	}

	/* reset for next revision walk */
377 378 379 380
	clear_commit_marks((struct commit *)o1,
			SEEN | UNINTERESTING | SHOWN | ADDED);
	clear_commit_marks((struct commit *)o2,
			SEEN | UNINTERESTING | SHOWN | ADDED);
381 382 383 384
	o1->flags = flags1;
	o2->flags = flags2;
}

385 386
static void gen_message_id(char *dest, unsigned int length, char *base)
{
387
	const char *committer = git_committer_info(-1);
388 389 390 391
	const char *email_start = strrchr(committer, '<');
	const char *email_end = strrchr(committer, '>');
	if(!email_start || !email_end || email_start > email_end - 1)
		die("Could not extract email from committer identity.");
392 393 394
	snprintf(dest, length, "%s.%lu.git.%.*s", base,
		 (unsigned long) time(NULL),
		 (int)(email_end - email_start - 1), email_start + 1);
395 396
}

397
int cmd_format_patch(int argc, const char **argv, const char *prefix)
398 399 400 401
{
	struct commit *commit;
	struct commit **list = NULL;
	struct rev_info rev;
402
	int nr = 0, total, i, j;
403
	int use_stdout = 0;
404
	int numbered = 0;
405
	int start_number = -1;
406
	int keep_subject = 0;
407
	int ignore_if_in_upstream = 0;
408
	int thread = 0;
409
	const char *in_reply_to = NULL;
410
	struct diff_options patch_id_opts;
J
Junio C Hamano 已提交
411
	char *add_signoff = NULL;
412 413
	char message_id[1024];
	char ref_message_id[1024];
414

415
	git_config(git_format_config);
416
	init_revisions(&rev, prefix);
417 418 419 420 421
	rev.commit_format = CMIT_FMT_EMAIL;
	rev.verbose_header = 1;
	rev.diff = 1;
	rev.combine_merges = 0;
	rev.ignore_merges = 1;
422 423
	rev.diffopt.msg_sep = "";
	rev.diffopt.recursive = 1;
424

425 426
	rev.extra_headers = extra_headers;

427 428 429 430 431 432 433
	/*
	 * Parse the arguments before setup_revisions(), or something
	 * like "git fmt-patch -o a123 HEAD^.." may fail; a123 is
	 * possibly a valid SHA1.
	 */
	for (i = 1, j = 1; i < argc; i++) {
		if (!strcmp(argv[i], "--stdout"))
434
			use_stdout = 1;
435 436 437
		else if (!strcmp(argv[i], "-n") ||
				!strcmp(argv[i], "--numbered"))
			numbered = 1;
438 439 440 441 442 443 444
		else if (!strncmp(argv[i], "--start-number=", 15))
			start_number = strtol(argv[i] + 15, NULL, 10);
		else if (!strcmp(argv[i], "--start-number")) {
			i++;
			if (i == argc)
				die("Need a number for --start-number");
			start_number = strtol(argv[i], NULL, 10);
J
Junio C Hamano 已提交
445 446
		}
		else if (!strcmp(argv[i], "-k") ||
447 448 449
				!strcmp(argv[i], "--keep-subject")) {
			keep_subject = 1;
			rev.total = -1;
J
Junio C Hamano 已提交
450
		}
451 452
		else if (!strcmp(argv[i], "--output-directory") ||
			 !strcmp(argv[i], "-o")) {
453
			i++;
454 455 456 457 458
			if (argc <= i)
				die("Which directory?");
			if (output_directory)
				die("Two output directories?");
			output_directory = argv[i];
459
		}
J
Junio C Hamano 已提交
460 461
		else if (!strcmp(argv[i], "--signoff") ||
			 !strcmp(argv[i], "-s")) {
E
Eric W. Biederman 已提交
462 463 464 465
			const char *committer;
			const char *endpos;
			committer = git_committer_info(1);
			endpos = strchr(committer, '>');
J
Junio C Hamano 已提交
466 467 468 469 470 471
			if (!endpos)
				die("bogos committer info %s\n", committer);
			add_signoff = xmalloc(endpos - committer + 2);
			memcpy(add_signoff, committer, endpos - committer + 1);
			add_signoff[endpos - committer + 1] = 0;
		}
472 473 474 475
		else if (!strcmp(argv[i], "--attach"))
			rev.mime_boundary = git_version_string;
		else if (!strncmp(argv[i], "--attach=", 9))
			rev.mime_boundary = argv[i] + 9;
476 477
		else if (!strcmp(argv[i], "--ignore-if-in-upstream"))
			ignore_if_in_upstream = 1;
478 479
		else if (!strcmp(argv[i], "--thread"))
			thread = 1;
480 481 482 483 484 485 486 487
		else if (!strncmp(argv[i], "--in-reply-to=", 14))
			in_reply_to = argv[i] + 14;
		else if (!strcmp(argv[i], "--in-reply-to")) {
			i++;
			if (i == argc)
				die("Need a Message-Id for --in-reply-to");
			in_reply_to = argv[i];
		}
488 489
		else if (!strncmp(argv[i], "--suffix=", 9))
			fmt_patch_suffix = argv[i] + 9;
490
		else
491
			argv[j++] = argv[i];
492
	}
493 494
	argc = j;

495
	if (start_number < 0)
496
		start_number = 1;
497
	if (numbered && keep_subject)
498 499
		die ("-n and -k are mutually exclusive.");

500 501 502
	argc = setup_revisions(argc, argv, &rev, "HEAD");
	if (argc > 1)
		die ("unrecognized argument: %s", argv[1]);
503

504
	if (!rev.diffopt.output_format)
505
		rev.diffopt.output_format = DIFF_FORMAT_DIFFSTAT | DIFF_FORMAT_SUMMARY | DIFF_FORMAT_PATCH;
506

507 508 509
	if (!rev.diffopt.text)
		rev.diffopt.binary = 1;

510
	if (!output_directory && !use_stdout)
511 512
		output_directory = prefix;

513 514 515 516 517 518 519 520
	if (output_directory) {
		if (use_stdout)
			die("standard output, or directory, which one?");
		if (mkdir(output_directory, 0777) < 0 && errno != EEXIST)
			die("Could not create directory %s",
			    output_directory);
	}

521
	if (rev.pending.nr == 1) {
J
Junio C Hamano 已提交
522 523 524 525 526 527 528
		if (rev.max_count < 0) {
			rev.pending.objects[0].item->flags |= UNINTERESTING;
			add_head(&rev);
		}
		/* Otherwise, it is "format-patch -22 HEAD", and
		 * get_revision() would return only the specified count.
		 */
529 530
	}

531
	if (ignore_if_in_upstream)
532
		get_patch_ids(&rev, &patch_id_opts, prefix);
533

534 535 536
	if (!use_stdout)
		realstdout = fdopen(dup(1), "w");

537 538
	prepare_revision_walk(&rev);
	while ((commit = get_revision(&rev)) != NULL) {
539 540
		unsigned char sha1[20];

541 542 543
		/* ignore merges */
		if (commit->parents && commit->parents->next)
			continue;
544 545 546 547 548 549

		if (ignore_if_in_upstream &&
				!get_patch_id(commit, &patch_id_opts, sha1) &&
				lookup_object(sha1))
			continue;

550
		nr++;
J
Jonas Fonseca 已提交
551
		list = xrealloc(list, nr * sizeof(list[0]));
552 553
		list[nr - 1] = commit;
	}
554
	total = nr;
555
	if (numbered)
556
		rev.total = total + start_number - 1;
J
Junio C Hamano 已提交
557
	rev.add_signoff = add_signoff;
558
	rev.ref_message_id = in_reply_to;
559 560 561
	while (0 <= --nr) {
		int shown;
		commit = list[nr];
562
		rev.nr = total - nr + (start_number - 1);
563
		/* Make the second and subsequent mails replies to the first */
564 565 566 567 568 569 570 571 572 573
		if (thread) {
			if (nr == (total - 2)) {
				strncpy(ref_message_id, message_id,
					sizeof(ref_message_id));
				ref_message_id[sizeof(ref_message_id)-1]='\0';
				rev.ref_message_id = ref_message_id;
			}
			gen_message_id(message_id, sizeof(message_id),
				       sha1_to_hex(commit->object.sha1));
			rev.message_id = message_id;
574
		}
575
		if (!use_stdout)
576
			reopen_stdout(commit, rev.nr, keep_subject);
577 578 579
		shown = log_tree_commit(&rev, commit);
		free(commit->buffer);
		commit->buffer = NULL;
580 581 582 583 584 585 586 587 588

		/* We put one extra blank line between formatted
		 * patches and this flag is used by log-tree code
		 * to see if it needs to emit a LF before showing
		 * the log; when using one file per patch, we do
		 * not want the extra blank line.
		 */
		if (!use_stdout)
			rev.shown_one = 0;
589 590 591 592 593 594 595 596
		if (shown) {
			if (rev.mime_boundary)
				printf("\n--%s%s--\n\n\n",
				       mime_boundary_leader,
				       rev.mime_boundary);
			else
				printf("-- \n%s\n\n", git_version_string);
		}
597 598
		if (!use_stdout)
			fclose(stdout);
599 600 601 602 603
	}
	free(list);
	return 0;
}

R
Rene Scharfe 已提交
604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709
static int add_pending_commit(const char *arg, struct rev_info *revs, int flags)
{
	unsigned char sha1[20];
	if (get_sha1(arg, sha1) == 0) {
		struct commit *commit = lookup_commit_reference(sha1);
		if (commit) {
			commit->object.flags |= flags;
			add_pending_object(revs, &commit->object, arg);
			return 0;
		}
	}
	return -1;
}

static const char cherry_usage[] =
"git-cherry [-v] <upstream> [<head>] [<limit>]";
int cmd_cherry(int argc, const char **argv, const char *prefix)
{
	struct rev_info revs;
	struct diff_options patch_id_opts;
	struct commit *commit;
	struct commit_list *list = NULL;
	const char *upstream;
	const char *head = "HEAD";
	const char *limit = NULL;
	int verbose = 0;

	if (argc > 1 && !strcmp(argv[1], "-v")) {
		verbose = 1;
		argc--;
		argv++;
	}

	switch (argc) {
	case 4:
		limit = argv[3];
		/* FALLTHROUGH */
	case 3:
		head = argv[2];
		/* FALLTHROUGH */
	case 2:
		upstream = argv[1];
		break;
	default:
		usage(cherry_usage);
	}

	init_revisions(&revs, prefix);
	revs.diff = 1;
	revs.combine_merges = 0;
	revs.ignore_merges = 1;
	revs.diffopt.recursive = 1;

	if (add_pending_commit(head, &revs, 0))
		die("Unknown commit %s", head);
	if (add_pending_commit(upstream, &revs, UNINTERESTING))
		die("Unknown commit %s", upstream);

	/* Don't say anything if head and upstream are the same. */
	if (revs.pending.nr == 2) {
		struct object_array_entry *o = revs.pending.objects;
		if (hashcmp(o[0].item->sha1, o[1].item->sha1) == 0)
			return 0;
	}

	get_patch_ids(&revs, &patch_id_opts, prefix);

	if (limit && add_pending_commit(limit, &revs, UNINTERESTING))
		die("Unknown commit %s", limit);

	/* reverse the list of commits */
	prepare_revision_walk(&revs);
	while ((commit = get_revision(&revs)) != NULL) {
		/* ignore merges */
		if (commit->parents && commit->parents->next)
			continue;

		commit_list_insert(commit, &list);
	}

	while (list) {
		unsigned char sha1[20];
		char sign = '+';

		commit = list->item;
		if (!get_patch_id(commit, &patch_id_opts, sha1) &&
		    lookup_object(sha1))
			sign = '-';

		if (verbose) {
			static char buf[16384];
			pretty_print_commit(CMIT_FMT_ONELINE, commit, ~0,
			                    buf, sizeof(buf), 0, NULL, NULL, 0);
			printf("%c %s %s\n", sign,
			       sha1_to_hex(commit->object.sha1), buf);
		}
		else {
			printf("%c %s\n", sign,
			       sha1_to_hex(commit->object.sha1));
		}

		list = list->next;
	}

	return 0;
}