rev-parse.c 16.3 KB
Newer Older
1 2 3 4 5 6
/*
 * rev-parse.c
 *
 * Copyright (C) Linus Torvalds, 2005
 */
#include "cache.h"
7
#include "commit.h"
8
#include "refs.h"
9
#include "quote.h"
C
Christian Couder 已提交
10
#include "builtin.h"
11
#include "parse-options.h"
12

13 14 15 16 17 18
#define DO_REVS		1
#define DO_NOREV	2
#define DO_FLAGS	4
#define DO_NONFLAGS	8
static int filter = ~0;

19
static const char *def;
20

21 22 23
#define NORMAL 0
#define REVERSED 1
static int show_type = NORMAL;
24 25 26

#define SHOW_SYMBOLIC_ASIS 1
#define SHOW_SYMBOLIC_FULL 2
27 28
static int symbolic;
static int abbrev;
29 30
static int abbrev_ref;
static int abbrev_ref_strict;
31
static int output_sq;
32

33 34 35 36 37 38 39 40
/*
 * Some arguments are relevant "revision" arguments,
 * others are about output format or other details.
 * This sorts it all out.
 */
static int is_rev_argument(const char *arg)
{
	static const char *rev_args[] = {
41
		"--all",
42
		"--bisect",
43
		"--dense",
44
		"--branches=",
45
		"--branches",
46
		"--header",
J
Junio C Hamano 已提交
47
		"--ignore-missing",
48
		"--max-age=",
49 50
		"--max-count=",
		"--min-age=",
J
Junio C Hamano 已提交
51
		"--no-merges",
52 53 54 55
		"--min-parents=",
		"--no-min-parents",
		"--max-parents=",
		"--no-max-parents",
56
		"--objects",
J
Junio C Hamano 已提交
57
		"--objects-edge",
58 59
		"--parents",
		"--pretty",
60
		"--remotes=",
61
		"--remotes",
I
Ilari Liusvaara 已提交
62
		"--glob=",
63
		"--sparse",
64
		"--tags=",
65
		"--tags",
66
		"--topo-order",
67
		"--date-order",
68
		"--unpacked",
69 70 71 72
		NULL
	};
	const char **p = rev_args;

73 74 75 76
	/* accept -<digit>, like traditional "head" */
	if ((*arg == '-') && isdigit(arg[1]))
		return 1;

77 78 79 80 81 82
	for (;;) {
		const char *str = *p++;
		int len;
		if (!str)
			return 0;
		len = strlen(str);
83 84
		if (!strcmp(arg, str) ||
		    (str[len-1] == '=' && !strncmp(arg, str, len)))
85 86 87 88
			return 1;
	}
}

89
/* Output argument as a string, either SQ or normal */
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
static void show(const char *arg)
{
	if (output_sq) {
		int sq = '\'', ch;

		putchar(sq);
		while ((ch = *arg++)) {
			if (ch == sq)
				fputs("'\\'", stdout);
			putchar(ch);
		}
		putchar(sq);
		putchar(' ');
	}
	else
		puts(arg);
}

108 109 110 111 112 113 114 115
/* Like show(), but with a negation prefix according to type */
static void show_with_type(int type, const char *arg)
{
	if (type != show_type)
		putchar('^');
	show(arg);
}

116
/* Output a revision, only if filter allows it */
117
static void show_rev(int type, const unsigned char *sha1, const char *name)
118
{
119
	if (!(filter & DO_REVS))
120
		return;
121
	def = NULL;
122

123 124
	if ((symbolic || abbrev_ref) && name) {
		if (symbolic == SHOW_SYMBOLIC_FULL || abbrev_ref) {
125 126 127 128 129 130 131 132 133 134 135 136 137 138
			unsigned char discard[20];
			char *full;

			switch (dwim_ref(name, strlen(name), discard, &full)) {
			case 0:
				/*
				 * Not found -- not a ref.  We could
				 * emit "name" here, but symbolic-full
				 * users are interested in finding the
				 * refs spelled in full, and they would
				 * need to filter non-refs if we did so.
				 */
				break;
			case 1: /* happy */
139 140 141
				if (abbrev_ref)
					full = shorten_unambiguous_ref(full,
						abbrev_ref_strict);
142
				show_with_type(type, full);
143 144 145 146 147 148
				break;
			default: /* ambiguous */
				error("refname '%s' is ambiguous", name);
				break;
			}
		} else {
149
			show_with_type(type, name);
150 151
		}
	}
J
Junio C Hamano 已提交
152
	else if (abbrev)
153
		show_with_type(type, find_unique_abbrev(sha1, abbrev));
154
	else
155
		show_with_type(type, sha1_to_hex(sha1));
156 157
}

158
/* Output a flag, only if filter allows it. */
159
static int show_flag(const char *arg)
160
{
161
	if (!(filter & DO_FLAGS))
162 163
		return 0;
	if (filter & (is_rev_argument(arg) ? DO_REVS : DO_NOREV)) {
164
		show(arg);
165 166 167
		return 1;
	}
	return 0;
168 169
}

170
static int show_default(void)
171
{
172
	const char *s = def;
173 174 175 176 177

	if (s) {
		unsigned char sha1[20];

		def = NULL;
178
		if (!get_sha1(s, sha1)) {
179
			show_rev(NORMAL, sha1, s);
180
			return 1;
181 182
		}
	}
183
	return 0;
184 185
}

186
static int show_reference(const char *refname, const unsigned char *sha1, int flag, void *cb_data)
187
{
188
	show_rev(NORMAL, sha1, refname);
189 190 191
	return 0;
}

192 193 194 195 196 197
static int anti_reference(const char *refname, const unsigned char *sha1, int flag, void *cb_data)
{
	show_rev(REVERSED, sha1, refname);
	return 0;
}

198 199 200 201 202 203 204
static void show_datestring(const char *flag, const char *datestr)
{
	static char buffer[100];

	/* date handling requires both flags and revs */
	if ((filter & (DO_FLAGS | DO_REVS)) != (DO_FLAGS | DO_REVS))
		return;
205
	snprintf(buffer, sizeof(buffer), "%s%lu", flag, approxidate(datestr));
206 207 208
	show(buffer);
}

209
static int show_file(const char *arg)
210
{
211
	show_default();
212
	if ((filter & (DO_NONFLAGS|DO_NOREV)) == (DO_NONFLAGS|DO_NOREV)) {
213
		show(arg);
214 215 216
		return 1;
	}
	return 0;
217 218
}

219
static int try_difference(const char *arg)
S
Santi Béjar 已提交
220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263
{
	char *dotdot;
	unsigned char sha1[20];
	unsigned char end[20];
	const char *next;
	const char *this;
	int symmetric;

	if (!(dotdot = strstr(arg, "..")))
		return 0;
	next = dotdot + 2;
	this = arg;
	symmetric = (*next == '.');

	*dotdot = 0;
	next += symmetric;

	if (!*next)
		next = "HEAD";
	if (dotdot == arg)
		this = "HEAD";
	if (!get_sha1(this, sha1) && !get_sha1(next, end)) {
		show_rev(NORMAL, end, next);
		show_rev(symmetric ? NORMAL : REVERSED, sha1, this);
		if (symmetric) {
			struct commit_list *exclude;
			struct commit *a, *b;
			a = lookup_commit_reference(sha1);
			b = lookup_commit_reference(end);
			exclude = get_merge_bases(a, b, 1);
			while (exclude) {
				struct commit_list *n = exclude->next;
				show_rev(REVERSED,
					 exclude->item->object.sha1,NULL);
				free(exclude);
				exclude = n;
			}
		}
		return 1;
	}
	*dotdot = '.';
	return 0;
}

264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293
static int try_parent_shorthands(const char *arg)
{
	char *dotdot;
	unsigned char sha1[20];
	struct commit *commit;
	struct commit_list *parents;
	int parents_only;

	if ((dotdot = strstr(arg, "^!")))
		parents_only = 0;
	else if ((dotdot = strstr(arg, "^@")))
		parents_only = 1;

	if (!dotdot || dotdot[2])
		return 0;

	*dotdot = 0;
	if (get_sha1(arg, sha1))
		return 0;

	if (!parents_only)
		show_rev(NORMAL, sha1, arg);
	commit = lookup_commit_reference(sha1);
	for (parents = commit->parents; parents; parents = parents->next)
		show_rev(parents_only ? NORMAL : REVERSED,
				parents->item->object.sha1, arg);

	return 1;
}

294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318
static int parseopt_dump(const struct option *o, const char *arg, int unset)
{
	struct strbuf *parsed = o->value;
	if (unset)
		strbuf_addf(parsed, " --no-%s", o->long_name);
	else if (o->short_name)
		strbuf_addf(parsed, " -%c", o->short_name);
	else
		strbuf_addf(parsed, " --%s", o->long_name);
	if (arg) {
		strbuf_addch(parsed, ' ');
		sq_quote_buf(parsed, arg);
	}
	return 0;
}

static const char *skipspaces(const char *s)
{
	while (isspace(*s))
		s++;
	return s;
}

static int cmd_parseopt(int argc, const char **argv, const char *prefix)
{
319
	static int keep_dashdash = 0, stop_at_non_option = 0;
320
	static char const * const parseopt_usage[] = {
S
Stephan Beyer 已提交
321
		"git rev-parse --parseopt [options] -- [<args>...]",
322 323 324 325 326
		NULL
	};
	static struct option parseopt_opts[] = {
		OPT_BOOLEAN(0, "keep-dashdash", &keep_dashdash,
					"keep the `--` passed as an arg"),
327 328 329
		OPT_BOOLEAN(0, "stop-at-non-option", &stop_at_non_option,
					"stop parsing after the "
					"first non-option argument"),
330 331 332
		OPT_END(),
	};

333
	struct strbuf sb = STRBUF_INIT, parsed = STRBUF_INIT;
334 335 336 337 338
	const char **usage = NULL;
	struct option *opts = NULL;
	int onb = 0, osz = 0, unb = 0, usz = 0;

	strbuf_addstr(&parsed, "set --");
339
	argc = parse_options(argc, argv, prefix, parseopt_opts, parseopt_usage,
340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372
	                     PARSE_OPT_KEEP_DASHDASH);
	if (argc < 1 || strcmp(argv[0], "--"))
		usage_with_options(parseopt_usage, parseopt_opts);

	/* get the usage up to the first line with a -- on it */
	for (;;) {
		if (strbuf_getline(&sb, stdin, '\n') == EOF)
			die("premature end of input");
		ALLOC_GROW(usage, unb + 1, usz);
		if (!strcmp("--", sb.buf)) {
			if (unb < 1)
				die("no usage string given before the `--' separator");
			usage[unb] = NULL;
			break;
		}
		usage[unb++] = strbuf_detach(&sb, NULL);
	}

	/* parse: (<short>|<short>,<long>|<long>)[=?]? SP+ <help> */
	while (strbuf_getline(&sb, stdin, '\n') != EOF) {
		const char *s;
		struct option *o;

		if (!sb.len)
			continue;

		ALLOC_GROW(opts, onb + 1, osz);
		memset(opts + onb, 0, sizeof(opts[onb]));

		o = &opts[onb++];
		s = strchr(sb.buf, ' ');
		if (!s || *sb.buf == ' ') {
			o->type = OPTION_GROUP;
373
			o->help = xstrdup(skipspaces(sb.buf));
374 375 376 377 378 379
			continue;
		}

		o->type = OPTION_CALLBACK;
		o->help = xstrdup(skipspaces(s));
		o->value = &parsed;
380
		o->flags = PARSE_OPT_NOARG;
381
		o->callback = &parseopt_dump;
382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397
		while (s > sb.buf && strchr("*=?!", s[-1])) {
			switch (*--s) {
			case '=':
				o->flags &= ~PARSE_OPT_NOARG;
				break;
			case '?':
				o->flags &= ~PARSE_OPT_NOARG;
				o->flags |= PARSE_OPT_OPTARG;
				break;
			case '!':
				o->flags |= PARSE_OPT_NONEG;
				break;
			case '*':
				o->flags |= PARSE_OPT_HIDDEN;
				break;
			}
398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413
		}

		if (s - sb.buf == 1) /* short option only */
			o->short_name = *sb.buf;
		else if (sb.buf[1] != ',') /* long option only */
			o->long_name = xmemdupz(sb.buf, s - sb.buf);
		else {
			o->short_name = *sb.buf;
			o->long_name = xmemdupz(sb.buf + 2, s - sb.buf - 2);
		}
	}
	strbuf_release(&sb);

	/* put an OPT_END() */
	ALLOC_GROW(opts, onb + 1, osz);
	memset(opts + onb, 0, sizeof(opts[onb]));
414
	argc = parse_options(argc, argv, prefix, opts, usage,
415
			(keep_dashdash ? PARSE_OPT_KEEP_DASHDASH : 0) |
J
Junio C Hamano 已提交
416
			(stop_at_non_option ? PARSE_OPT_STOP_AT_NON_OPTION : 0) |
417
			PARSE_OPT_SHELL_EVAL);
418 419

	strbuf_addf(&parsed, " --");
420
	sq_quote_argv(&parsed, argv, 0);
421 422 423 424
	puts(parsed.buf);
	return 0;
}

425 426 427 428 429 430 431 432 433 434 435 436
static int cmd_sq_quote(int argc, const char **argv)
{
	struct strbuf buf = STRBUF_INIT;

	if (argc)
		sq_quote_argv(&buf, argv, 0);
	printf("%s\n", buf.buf);
	strbuf_release(&buf);

	return 0;
}

437 438 439 440 441 442 443 444
static void die_no_single_rev(int quiet)
{
	if (quiet)
		exit(1);
	else
		die("Needed a single revision");
}

445 446 447 448 449 450 451
static const char builtin_rev_parse_usage[] =
"git rev-parse --parseopt [options] -- [<args>...]\n"
"   or: git rev-parse --sq-quote [<arg>...]\n"
"   or: git rev-parse [options] [<arg>...]\n"
"\n"
"Run \"git rev-parse --parseopt -h\" for more information on the first usage.";

452
int cmd_rev_parse(int argc, const char **argv, const char *prefix)
453
{
454
	int i, as_is = 0, verify = 0, quiet = 0, revs_count = 0, type = 0;
455
	unsigned char sha1[20];
456
	const char *name = NULL;
457

458 459 460
	if (argc > 1 && !strcmp("--parseopt", argv[1]))
		return cmd_parseopt(argc - 1, argv + 1, prefix);

461 462 463
	if (argc > 1 && !strcmp("--sq-quote", argv[1]))
		return cmd_sq_quote(argc - 2, argv + 2);

464 465 466 467 468 469 470
	if (argc == 2 && !strcmp("--local-env-vars", argv[1])) {
		int i;
		for (i = 0; local_repo_env[i]; i++)
			printf("%s\n", local_repo_env[i]);
		return 0;
	}

471 472 473 474 475 476 477 478
	if (argc > 2 && !strcmp(argv[1], "--resolve-git-dir")) {
		const char *gitdir = resolve_gitdir(argv[2]);
		if (!gitdir)
			die("not a gitdir '%s'", argv[2]);
		puts(gitdir);
		return 0;
	}

479 480 481
	if (argc > 1 && !strcmp("-h", argv[1]))
		usage(builtin_rev_parse_usage);

J
Junio C Hamano 已提交
482
	prefix = setup_git_directory();
483
	git_config(git_default_config, NULL);
484
	for (i = 1; i < argc; i++) {
485
		const char *arg = argv[i];
486

487
		if (as_is) {
488
			if (show_file(arg) && as_is < 2)
489
				verify_filename(prefix, arg);
490 491
			continue;
		}
492 493 494 495 496 497 498 499 500
		if (!strcmp(arg,"-n")) {
			if (++i >= argc)
				die("-n requires an argument");
			if ((filter & DO_FLAGS) && (filter & DO_REVS)) {
				show(arg);
				show(argv[i]);
			}
			continue;
		}
501
		if (!prefixcmp(arg, "-n")) {
502 503 504 505 506
			if ((filter & DO_FLAGS) && (filter & DO_REVS))
				show(arg);
			continue;
		}

507 508
		if (*arg == '-') {
			if (!strcmp(arg, "--")) {
509
				as_is = 2;
510 511 512
				/* Pass on the "--" if we show anything but files.. */
				if (filter & (DO_FLAGS | DO_REVS))
					show_file(arg);
513
				continue;
514 515 516 517 518 519
			}
			if (!strcmp(arg, "--default")) {
				def = argv[i+1];
				i++;
				continue;
			}
520
			if (!strcmp(arg, "--revs-only")) {
521
				filter &= ~DO_NOREV;
522 523 524
				continue;
			}
			if (!strcmp(arg, "--no-revs")) {
525
				filter &= ~DO_REVS;
526 527
				continue;
			}
528
			if (!strcmp(arg, "--flags")) {
529
				filter &= ~DO_NONFLAGS;
530 531 532
				continue;
			}
			if (!strcmp(arg, "--no-flags")) {
533
				filter &= ~DO_FLAGS;
534 535
				continue;
			}
536
			if (!strcmp(arg, "--verify")) {
537 538
				filter &= ~(DO_FLAGS|DO_NOREV);
				verify = 1;
539
				continue;
540
			}
541 542 543 544
			if (!strcmp(arg, "--quiet") || !strcmp(arg, "-q")) {
				quiet = 1;
				continue;
			}
545
			if (!strcmp(arg, "--short") ||
546
			    !prefixcmp(arg, "--short=")) {
J
Junio C Hamano 已提交
547 548 549
				filter &= ~(DO_FLAGS|DO_NOREV);
				verify = 1;
				abbrev = DEFAULT_ABBREV;
550 551
				if (arg[7] == '=')
					abbrev = strtoul(arg + 8, NULL, 10);
552 553 554 555
				if (abbrev < MINIMUM_ABBREV)
					abbrev = MINIMUM_ABBREV;
				else if (40 <= abbrev)
					abbrev = 40;
J
Junio C Hamano 已提交
556 557
				continue;
			}
558 559 560 561
			if (!strcmp(arg, "--sq")) {
				output_sq = 1;
				continue;
			}
562 563 564 565
			if (!strcmp(arg, "--not")) {
				show_type ^= REVERSED;
				continue;
			}
566
			if (!strcmp(arg, "--symbolic")) {
567 568 569 570 571
				symbolic = SHOW_SYMBOLIC_ASIS;
				continue;
			}
			if (!strcmp(arg, "--symbolic-full-name")) {
				symbolic = SHOW_SYMBOLIC_FULL;
572 573
				continue;
			}
574 575 576 577 578 579 580 581 582 583 584 585 586 587
			if (!prefixcmp(arg, "--abbrev-ref") &&
			    (!arg[12] || arg[12] == '=')) {
				abbrev_ref = 1;
				abbrev_ref_strict = warn_ambiguous_refs;
				if (arg[12] == '=') {
					if (!strcmp(arg + 13, "strict"))
						abbrev_ref_strict = 1;
					else if (!strcmp(arg + 13, "loose"))
						abbrev_ref_strict = 0;
					else
						die("unknown mode for %s", arg);
				}
				continue;
			}
588
			if (!strcmp(arg, "--all")) {
589
				for_each_ref(show_reference, NULL);
590 591
				continue;
			}
592 593 594 595 596
			if (!strcmp(arg, "--bisect")) {
				for_each_ref_in("refs/bisect/bad", show_reference, NULL);
				for_each_ref_in("refs/bisect/good", anti_reference, NULL);
				continue;
			}
597 598 599 600 601
			if (!prefixcmp(arg, "--branches=")) {
				for_each_glob_ref_in(show_reference, arg + 11,
					"refs/heads/", NULL);
				continue;
			}
602
			if (!strcmp(arg, "--branches")) {
603
				for_each_branch_ref(show_reference, NULL);
604 605
				continue;
			}
606 607 608 609 610
			if (!prefixcmp(arg, "--tags=")) {
				for_each_glob_ref_in(show_reference, arg + 7,
					"refs/tags/", NULL);
				continue;
			}
611
			if (!strcmp(arg, "--tags")) {
612
				for_each_tag_ref(show_reference, NULL);
613 614
				continue;
			}
I
Ilari Liusvaara 已提交
615 616 617 618
			if (!prefixcmp(arg, "--glob=")) {
				for_each_glob_ref(show_reference, arg + 7, NULL);
				continue;
			}
619 620 621 622 623
			if (!prefixcmp(arg, "--remotes=")) {
				for_each_glob_ref_in(show_reference, arg + 10,
					"refs/remotes/", NULL);
				continue;
			}
624
			if (!strcmp(arg, "--remotes")) {
625
				for_each_remote_ref(show_reference, NULL);
626 627
				continue;
			}
628 629 630 631 632 633
			if (!strcmp(arg, "--show-toplevel")) {
				const char *work_tree = get_git_work_tree();
				if (work_tree)
					puts(work_tree);
				continue;
			}
634
			if (!strcmp(arg, "--show-prefix")) {
635 636
				if (prefix)
					puts(prefix);
637 638
				continue;
			}
J
Junio C Hamano 已提交
639 640
			if (!strcmp(arg, "--show-cdup")) {
				const char *pfx = prefix;
641 642 643 644 645 646 647
				if (!is_inside_work_tree()) {
					const char *work_tree =
						get_git_work_tree();
					if (work_tree)
						printf("%s\n", work_tree);
					continue;
				}
J
Junio C Hamano 已提交
648 649 650 651 652 653 654 655 656 657
				while (pfx) {
					pfx = strchr(pfx, '/');
					if (pfx) {
						pfx++;
						printf("../");
					}
				}
				putchar('\n');
				continue;
			}
658 659 660
			if (!strcmp(arg, "--git-dir")) {
				const char *gitdir = getenv(GIT_DIR_ENVIRONMENT);
				static char cwd[PATH_MAX];
661
				int len;
662 663 664 665 666 667 668 669 670
				if (gitdir) {
					puts(gitdir);
					continue;
				}
				if (!prefix) {
					puts(".git");
					continue;
				}
				if (!getcwd(cwd, PATH_MAX))
671
					die_errno("unable to get current working directory");
672 673
				len = strlen(cwd);
				printf("%s%s.git\n", cwd, len && cwd[len-1] != '/' ? "/" : "");
674 675
				continue;
			}
676 677 678 679 680
			if (!strcmp(arg, "--is-inside-git-dir")) {
				printf("%s\n", is_inside_git_dir() ? "true"
						: "false");
				continue;
			}
681 682 683 684 685
			if (!strcmp(arg, "--is-inside-work-tree")) {
				printf("%s\n", is_inside_work_tree() ? "true"
						: "false");
				continue;
			}
686 687 688 689 690
			if (!strcmp(arg, "--is-bare-repository")) {
				printf("%s\n", is_bare_repository() ? "true"
						: "false");
				continue;
			}
691
			if (!prefixcmp(arg, "--since=")) {
692 693 694
				show_datestring("--max-age=", arg+8);
				continue;
			}
695
			if (!prefixcmp(arg, "--after=")) {
696 697 698
				show_datestring("--max-age=", arg+8);
				continue;
			}
699
			if (!prefixcmp(arg, "--before=")) {
700 701 702
				show_datestring("--min-age=", arg+9);
				continue;
			}
703
			if (!prefixcmp(arg, "--until=")) {
704 705 706
				show_datestring("--min-age=", arg+8);
				continue;
			}
707
			if (show_flag(arg) && verify)
708
				die_no_single_rev(quiet);
709 710
			continue;
		}
711 712

		/* Not a flag argument */
S
Santi Béjar 已提交
713 714
		if (try_difference(arg))
			continue;
715 716
		if (try_parent_shorthands(arg))
			continue;
717 718 719 720 721
		name = arg;
		type = NORMAL;
		if (*arg == '^') {
			name++;
			type = REVERSED;
722
		}
723 724 725 726 727
		if (!get_sha1(name, sha1)) {
			if (verify)
				revs_count++;
			else
				show_rev(type, sha1, name);
728 729
			continue;
		}
730 731
		if (verify)
			die_no_single_rev(quiet);
732 733 734
		as_is = 1;
		if (!show_file(arg))
			continue;
735
		verify_filename(prefix, arg);
736
	}
737 738 739 740 741 742
	if (verify) {
		if (revs_count == 1) {
			show_rev(type, sha1, name);
			return 0;
		} else if (revs_count == 0 && show_default())
			return 0;
743
		die_no_single_rev(quiet);
744 745
	} else
		show_default();
746 747
	return 0;
}