rev-parse --glob
[git/git.git] / builtin-rev-parse.c
CommitLineData
178cb243
LT
1/*
2 * rev-parse.c
3 *
4 * Copyright (C) Linus Torvalds, 2005
5 */
6#include "cache.h"
a8be83fe 7#include "commit.h"
960bba0d 8#include "refs.h"
c1babb1d 9#include "quote.h"
895f10c3 10#include "builtin.h"
21d47835 11#include "parse-options.h"
a8be83fe 12
4866ccf0
JH
13#define DO_REVS 1
14#define DO_NOREV 2
15#define DO_FLAGS 4
16#define DO_NONFLAGS 8
17static int filter = ~0;
18
96f1e58f 19static const char *def;
023d66ed 20
042a4ed7
LT
21#define NORMAL 0
22#define REVERSED 1
23static int show_type = NORMAL;
a6d97d49
JH
24
25#define SHOW_SYMBOLIC_ASIS 1
26#define SHOW_SYMBOLIC_FULL 2
96f1e58f
DR
27static int symbolic;
28static int abbrev;
a45d3469
BW
29static int abbrev_ref;
30static int abbrev_ref_strict;
96f1e58f 31static int output_sq;
4866ccf0 32
921d865e
LT
33/*
34 * Some arguments are relevant "revision" arguments,
35 * others are about output format or other details.
36 * This sorts it all out.
37 */
38static int is_rev_argument(const char *arg)
39{
40 static const char *rev_args[] = {
e091eb93 41 "--all",
4866ccf0 42 "--bisect",
5a83f3be 43 "--dense",
a62be77f 44 "--branches",
4866ccf0 45 "--header",
921d865e 46 "--max-age=",
4866ccf0 47 "--max-count=",
4866ccf0 48 "--min-age=",
5ccfb758 49 "--no-merges",
4866ccf0 50 "--objects",
c6496575 51 "--objects-edge",
4866ccf0
JH
52 "--parents",
53 "--pretty",
a62be77f 54 "--remotes",
d08bae7e 55 "--glob=",
5a83f3be 56 "--sparse",
a62be77f 57 "--tags",
4866ccf0 58 "--topo-order",
4c8725f1 59 "--date-order",
4866ccf0 60 "--unpacked",
921d865e
LT
61 NULL
62 };
63 const char **p = rev_args;
64
8233340c
EW
65 /* accept -<digit>, like traditional "head" */
66 if ((*arg == '-') && isdigit(arg[1]))
67 return 1;
68
921d865e
LT
69 for (;;) {
70 const char *str = *p++;
71 int len;
72 if (!str)
73 return 0;
74 len = strlen(str);
4866ccf0
JH
75 if (!strcmp(arg, str) ||
76 (str[len-1] == '=' && !strncmp(arg, str, len)))
921d865e
LT
77 return 1;
78 }
79}
80
4866ccf0 81/* Output argument as a string, either SQ or normal */
5bb2c65a
JH
82static void show(const char *arg)
83{
84 if (output_sq) {
85 int sq = '\'', ch;
86
87 putchar(sq);
88 while ((ch = *arg++)) {
89 if (ch == sq)
90 fputs("'\\'", stdout);
91 putchar(ch);
92 }
93 putchar(sq);
94 putchar(' ');
95 }
96 else
97 puts(arg);
98}
99
e00f3790
JS
100/* Like show(), but with a negation prefix according to type */
101static void show_with_type(int type, const char *arg)
102{
103 if (type != show_type)
104 putchar('^');
105 show(arg);
106}
107
4866ccf0 108/* Output a revision, only if filter allows it */
30b96fce 109static void show_rev(int type, const unsigned char *sha1, const char *name)
023d66ed 110{
4866ccf0 111 if (!(filter & DO_REVS))
023d66ed 112 return;
4866ccf0 113 def = NULL;
5bb2c65a 114
a45d3469
BW
115 if ((symbolic || abbrev_ref) && name) {
116 if (symbolic == SHOW_SYMBOLIC_FULL || abbrev_ref) {
a6d97d49
JH
117 unsigned char discard[20];
118 char *full;
119
120 switch (dwim_ref(name, strlen(name), discard, &full)) {
121 case 0:
122 /*
123 * Not found -- not a ref. We could
124 * emit "name" here, but symbolic-full
125 * users are interested in finding the
126 * refs spelled in full, and they would
127 * need to filter non-refs if we did so.
128 */
129 break;
130 case 1: /* happy */
a45d3469
BW
131 if (abbrev_ref)
132 full = shorten_unambiguous_ref(full,
133 abbrev_ref_strict);
e00f3790 134 show_with_type(type, full);
a6d97d49
JH
135 break;
136 default: /* ambiguous */
137 error("refname '%s' is ambiguous", name);
138 break;
139 }
140 } else {
e00f3790 141 show_with_type(type, name);
a6d97d49
JH
142 }
143 }
d5012508 144 else if (abbrev)
e00f3790 145 show_with_type(type, find_unique_abbrev(sha1, abbrev));
30b96fce 146 else
e00f3790 147 show_with_type(type, sha1_to_hex(sha1));
023d66ed
LT
148}
149
4866ccf0 150/* Output a flag, only if filter allows it. */
16cee38a 151static int show_flag(const char *arg)
023d66ed 152{
4866ccf0 153 if (!(filter & DO_FLAGS))
9523a4c2
LT
154 return 0;
155 if (filter & (is_rev_argument(arg) ? DO_REVS : DO_NOREV)) {
0360e99d 156 show(arg);
9523a4c2
LT
157 return 1;
158 }
159 return 0;
023d66ed
LT
160}
161
dfd1b749 162static int show_default(void)
023d66ed 163{
16cee38a 164 const char *s = def;
023d66ed
LT
165
166 if (s) {
167 unsigned char sha1[20];
168
169 def = NULL;
9938af6a 170 if (!get_sha1(s, sha1)) {
30b96fce 171 show_rev(NORMAL, sha1, s);
dfd1b749 172 return 1;
023d66ed 173 }
023d66ed 174 }
dfd1b749 175 return 0;
023d66ed
LT
176}
177
8da19775 178static int show_reference(const char *refname, const unsigned char *sha1, int flag, void *cb_data)
960bba0d 179{
30b96fce 180 show_rev(NORMAL, sha1, refname);
960bba0d
LT
181 return 0;
182}
183
ad3f9a71
LT
184static int anti_reference(const char *refname, const unsigned char *sha1, int flag, void *cb_data)
185{
186 show_rev(REVERSED, sha1, refname);
187 return 0;
188}
189
c1babb1d
LT
190static void show_datestring(const char *flag, const char *datestr)
191{
c1babb1d 192 static char buffer[100];
c1babb1d
LT
193
194 /* date handling requires both flags and revs */
195 if ((filter & (DO_FLAGS | DO_REVS)) != (DO_FLAGS | DO_REVS))
196 return;
3c07b1d1 197 snprintf(buffer, sizeof(buffer), "%s%lu", flag, approxidate(datestr));
c1babb1d
LT
198 show(buffer);
199}
200
9ad0a933 201static int show_file(const char *arg)
7a3dd472 202{
7b34c2fa 203 show_default();
9ad0a933 204 if ((filter & (DO_NONFLAGS|DO_NOREV)) == (DO_NONFLAGS|DO_NOREV)) {
7a3dd472 205 show(arg);
9ad0a933
LT
206 return 1;
207 }
208 return 0;
7a3dd472
LT
209}
210
b7d936b2 211static int try_difference(const char *arg)
3dd4e732
SB
212{
213 char *dotdot;
214 unsigned char sha1[20];
215 unsigned char end[20];
216 const char *next;
217 const char *this;
218 int symmetric;
219
220 if (!(dotdot = strstr(arg, "..")))
221 return 0;
222 next = dotdot + 2;
223 this = arg;
224 symmetric = (*next == '.');
225
226 *dotdot = 0;
227 next += symmetric;
228
229 if (!*next)
230 next = "HEAD";
231 if (dotdot == arg)
232 this = "HEAD";
233 if (!get_sha1(this, sha1) && !get_sha1(next, end)) {
234 show_rev(NORMAL, end, next);
235 show_rev(symmetric ? NORMAL : REVERSED, sha1, this);
236 if (symmetric) {
237 struct commit_list *exclude;
238 struct commit *a, *b;
239 a = lookup_commit_reference(sha1);
240 b = lookup_commit_reference(end);
241 exclude = get_merge_bases(a, b, 1);
242 while (exclude) {
243 struct commit_list *n = exclude->next;
244 show_rev(REVERSED,
245 exclude->item->object.sha1,NULL);
246 free(exclude);
247 exclude = n;
248 }
249 }
250 return 1;
251 }
252 *dotdot = '.';
253 return 0;
254}
255
2122f8b9
BS
256static int try_parent_shorthands(const char *arg)
257{
258 char *dotdot;
259 unsigned char sha1[20];
260 struct commit *commit;
261 struct commit_list *parents;
262 int parents_only;
263
264 if ((dotdot = strstr(arg, "^!")))
265 parents_only = 0;
266 else if ((dotdot = strstr(arg, "^@")))
267 parents_only = 1;
268
269 if (!dotdot || dotdot[2])
270 return 0;
271
272 *dotdot = 0;
273 if (get_sha1(arg, sha1))
274 return 0;
275
276 if (!parents_only)
277 show_rev(NORMAL, sha1, arg);
278 commit = lookup_commit_reference(sha1);
279 for (parents = commit->parents; parents; parents = parents->next)
280 show_rev(parents_only ? NORMAL : REVERSED,
281 parents->item->object.sha1, arg);
282
283 return 1;
284}
285
21d47835
PH
286static int parseopt_dump(const struct option *o, const char *arg, int unset)
287{
288 struct strbuf *parsed = o->value;
289 if (unset)
290 strbuf_addf(parsed, " --no-%s", o->long_name);
291 else if (o->short_name)
292 strbuf_addf(parsed, " -%c", o->short_name);
293 else
294 strbuf_addf(parsed, " --%s", o->long_name);
295 if (arg) {
296 strbuf_addch(parsed, ' ');
297 sq_quote_buf(parsed, arg);
298 }
299 return 0;
300}
301
302static const char *skipspaces(const char *s)
303{
304 while (isspace(*s))
305 s++;
306 return s;
307}
308
309static int cmd_parseopt(int argc, const char **argv, const char *prefix)
310{
6e0800ef 311 static int keep_dashdash = 0, stop_at_non_option = 0;
21d47835 312 static char const * const parseopt_usage[] = {
1b1dd23f 313 "git rev-parse --parseopt [options] -- [<args>...]",
21d47835
PH
314 NULL
315 };
316 static struct option parseopt_opts[] = {
317 OPT_BOOLEAN(0, "keep-dashdash", &keep_dashdash,
318 "keep the `--` passed as an arg"),
6e0800ef
UKK
319 OPT_BOOLEAN(0, "stop-at-non-option", &stop_at_non_option,
320 "stop parsing after the "
321 "first non-option argument"),
21d47835
PH
322 OPT_END(),
323 };
324
f285a2d7 325 struct strbuf sb = STRBUF_INIT, parsed = STRBUF_INIT;
21d47835
PH
326 const char **usage = NULL;
327 struct option *opts = NULL;
328 int onb = 0, osz = 0, unb = 0, usz = 0;
329
21d47835 330 strbuf_addstr(&parsed, "set --");
37782920 331 argc = parse_options(argc, argv, prefix, parseopt_opts, parseopt_usage,
21d47835
PH
332 PARSE_OPT_KEEP_DASHDASH);
333 if (argc < 1 || strcmp(argv[0], "--"))
334 usage_with_options(parseopt_usage, parseopt_opts);
335
21d47835
PH
336 /* get the usage up to the first line with a -- on it */
337 for (;;) {
338 if (strbuf_getline(&sb, stdin, '\n') == EOF)
339 die("premature end of input");
340 ALLOC_GROW(usage, unb + 1, usz);
341 if (!strcmp("--", sb.buf)) {
342 if (unb < 1)
343 die("no usage string given before the `--' separator");
344 usage[unb] = NULL;
345 break;
346 }
347 usage[unb++] = strbuf_detach(&sb, NULL);
348 }
349
350 /* parse: (<short>|<short>,<long>|<long>)[=?]? SP+ <help> */
351 while (strbuf_getline(&sb, stdin, '\n') != EOF) {
352 const char *s;
353 struct option *o;
354
355 if (!sb.len)
356 continue;
357
358 ALLOC_GROW(opts, onb + 1, osz);
359 memset(opts + onb, 0, sizeof(opts[onb]));
360
361 o = &opts[onb++];
362 s = strchr(sb.buf, ' ');
363 if (!s || *sb.buf == ' ') {
364 o->type = OPTION_GROUP;
e1033436 365 o->help = xstrdup(skipspaces(sb.buf));
21d47835
PH
366 continue;
367 }
368
369 o->type = OPTION_CALLBACK;
370 o->help = xstrdup(skipspaces(s));
371 o->value = &parsed;
ff962a3f 372 o->flags = PARSE_OPT_NOARG;
21d47835 373 o->callback = &parseopt_dump;
ff962a3f
PH
374 while (s > sb.buf && strchr("*=?!", s[-1])) {
375 switch (*--s) {
376 case '=':
377 o->flags &= ~PARSE_OPT_NOARG;
378 break;
379 case '?':
380 o->flags &= ~PARSE_OPT_NOARG;
381 o->flags |= PARSE_OPT_OPTARG;
382 break;
383 case '!':
384 o->flags |= PARSE_OPT_NONEG;
385 break;
386 case '*':
387 o->flags |= PARSE_OPT_HIDDEN;
388 break;
389 }
21d47835
PH
390 }
391
392 if (s - sb.buf == 1) /* short option only */
393 o->short_name = *sb.buf;
394 else if (sb.buf[1] != ',') /* long option only */
395 o->long_name = xmemdupz(sb.buf, s - sb.buf);
396 else {
397 o->short_name = *sb.buf;
398 o->long_name = xmemdupz(sb.buf + 2, s - sb.buf - 2);
399 }
400 }
401 strbuf_release(&sb);
402
403 /* put an OPT_END() */
404 ALLOC_GROW(opts, onb + 1, osz);
405 memset(opts + onb, 0, sizeof(opts[onb]));
37782920 406 argc = parse_options(argc, argv, prefix, opts, usage,
6e0800ef
UKK
407 keep_dashdash ? PARSE_OPT_KEEP_DASHDASH : 0 |
408 stop_at_non_option ? PARSE_OPT_STOP_AT_NON_OPTION : 0);
21d47835
PH
409
410 strbuf_addf(&parsed, " --");
b319ce4c 411 sq_quote_argv(&parsed, argv, 0);
21d47835
PH
412 puts(parsed.buf);
413 return 0;
414}
415
50325377
CC
416static int cmd_sq_quote(int argc, const char **argv)
417{
418 struct strbuf buf = STRBUF_INIT;
419
420 if (argc)
421 sq_quote_argv(&buf, argv, 0);
422 printf("%s\n", buf.buf);
423 strbuf_release(&buf);
424
425 return 0;
426}
427
b1b35969
CC
428static void die_no_single_rev(int quiet)
429{
430 if (quiet)
431 exit(1);
432 else
433 die("Needed a single revision");
434}
435
7006b5be
JN
436static const char builtin_rev_parse_usage[] =
437"git rev-parse --parseopt [options] -- [<args>...]\n"
438" or: git rev-parse --sq-quote [<arg>...]\n"
439" or: git rev-parse [options] [<arg>...]\n"
440"\n"
441"Run \"git rev-parse --parseopt -h\" for more information on the first usage.";
442
a633fca0 443int cmd_rev_parse(int argc, const char **argv, const char *prefix)
178cb243 444{
dfd1b749 445 int i, as_is = 0, verify = 0, quiet = 0, revs_count = 0, type = 0;
178cb243 446 unsigned char sha1[20];
dfd1b749 447 const char *name = NULL;
a62be77f 448
21d47835
PH
449 if (argc > 1 && !strcmp("--parseopt", argv[1]))
450 return cmd_parseopt(argc - 1, argv + 1, prefix);
451
50325377
CC
452 if (argc > 1 && !strcmp("--sq-quote", argv[1]))
453 return cmd_sq_quote(argc - 2, argv + 2);
454
7006b5be
JN
455 if (argc > 1 && !strcmp("-h", argv[1]))
456 usage(builtin_rev_parse_usage);
457
5410a02a 458 prefix = setup_git_directory();
ef90d6d4 459 git_config(git_default_config, NULL);
178cb243 460 for (i = 1; i < argc; i++) {
16cee38a 461 const char *arg = argv[i];
fb18a2ed 462
178cb243 463 if (as_is) {
fb18a2ed 464 if (show_file(arg) && as_is < 2)
e23d0b4a 465 verify_filename(prefix, arg);
178cb243
LT
466 continue;
467 }
3af06987
EW
468 if (!strcmp(arg,"-n")) {
469 if (++i >= argc)
470 die("-n requires an argument");
471 if ((filter & DO_FLAGS) && (filter & DO_REVS)) {
472 show(arg);
473 show(argv[i]);
474 }
475 continue;
476 }
1968d77d 477 if (!prefixcmp(arg, "-n")) {
3af06987
EW
478 if ((filter & DO_FLAGS) && (filter & DO_REVS))
479 show(arg);
480 continue;
481 }
482
178cb243
LT
483 if (*arg == '-') {
484 if (!strcmp(arg, "--")) {
fb18a2ed 485 as_is = 2;
a08b6505
LT
486 /* Pass on the "--" if we show anything but files.. */
487 if (filter & (DO_FLAGS | DO_REVS))
488 show_file(arg);
4866ccf0 489 continue;
178cb243
LT
490 }
491 if (!strcmp(arg, "--default")) {
178cb243
LT
492 def = argv[i+1];
493 i++;
494 continue;
495 }
8ebb0184 496 if (!strcmp(arg, "--revs-only")) {
4866ccf0 497 filter &= ~DO_NOREV;
8ebb0184
LT
498 continue;
499 }
500 if (!strcmp(arg, "--no-revs")) {
4866ccf0 501 filter &= ~DO_REVS;
8ebb0184
LT
502 continue;
503 }
f79b65aa 504 if (!strcmp(arg, "--flags")) {
4866ccf0 505 filter &= ~DO_NONFLAGS;
f79b65aa
LT
506 continue;
507 }
508 if (!strcmp(arg, "--no-flags")) {
4866ccf0 509 filter &= ~DO_FLAGS;
f79b65aa
LT
510 continue;
511 }
023d66ed 512 if (!strcmp(arg, "--verify")) {
4866ccf0
JH
513 filter &= ~(DO_FLAGS|DO_NOREV);
514 verify = 1;
023d66ed 515 continue;
921d865e 516 }
b1b35969
CC
517 if (!strcmp(arg, "--quiet") || !strcmp(arg, "-q")) {
518 quiet = 1;
519 continue;
520 }
62a604ba 521 if (!strcmp(arg, "--short") ||
cc44c765 522 !prefixcmp(arg, "--short=")) {
d5012508
JH
523 filter &= ~(DO_FLAGS|DO_NOREV);
524 verify = 1;
525 abbrev = DEFAULT_ABBREV;
44de0da4
JF
526 if (arg[7] == '=')
527 abbrev = strtoul(arg + 8, NULL, 10);
1dc4fb84
JH
528 if (abbrev < MINIMUM_ABBREV)
529 abbrev = MINIMUM_ABBREV;
530 else if (40 <= abbrev)
531 abbrev = 40;
d5012508
JH
532 continue;
533 }
5bb2c65a
JH
534 if (!strcmp(arg, "--sq")) {
535 output_sq = 1;
536 continue;
537 }
042a4ed7
LT
538 if (!strcmp(arg, "--not")) {
539 show_type ^= REVERSED;
540 continue;
541 }
30b96fce 542 if (!strcmp(arg, "--symbolic")) {
a6d97d49
JH
543 symbolic = SHOW_SYMBOLIC_ASIS;
544 continue;
545 }
546 if (!strcmp(arg, "--symbolic-full-name")) {
547 symbolic = SHOW_SYMBOLIC_FULL;
30b96fce
JH
548 continue;
549 }
a45d3469
BW
550 if (!prefixcmp(arg, "--abbrev-ref") &&
551 (!arg[12] || arg[12] == '=')) {
552 abbrev_ref = 1;
553 abbrev_ref_strict = warn_ambiguous_refs;
554 if (arg[12] == '=') {
555 if (!strcmp(arg + 13, "strict"))
556 abbrev_ref_strict = 1;
557 else if (!strcmp(arg + 13, "loose"))
558 abbrev_ref_strict = 0;
559 else
560 die("unknown mode for %s", arg);
561 }
562 continue;
563 }
960bba0d 564 if (!strcmp(arg, "--all")) {
cb5d709f 565 for_each_ref(show_reference, NULL);
960bba0d
LT
566 continue;
567 }
ad3f9a71
LT
568 if (!strcmp(arg, "--bisect")) {
569 for_each_ref_in("refs/bisect/bad", show_reference, NULL);
570 for_each_ref_in("refs/bisect/good", anti_reference, NULL);
571 continue;
572 }
a62be77f 573 if (!strcmp(arg, "--branches")) {
cb5d709f 574 for_each_branch_ref(show_reference, NULL);
a62be77f
SE
575 continue;
576 }
577 if (!strcmp(arg, "--tags")) {
cb5d709f 578 for_each_tag_ref(show_reference, NULL);
a62be77f
SE
579 continue;
580 }
d08bae7e
IL
581 if (!prefixcmp(arg, "--glob=")) {
582 for_each_glob_ref(show_reference, arg + 7, NULL);
583 continue;
584 }
a62be77f 585 if (!strcmp(arg, "--remotes")) {
cb5d709f 586 for_each_remote_ref(show_reference, NULL);
a62be77f
SE
587 continue;
588 }
d288a700 589 if (!strcmp(arg, "--show-prefix")) {
4866ccf0
JH
590 if (prefix)
591 puts(prefix);
d288a700
LT
592 continue;
593 }
5f94c730
JH
594 if (!strcmp(arg, "--show-cdup")) {
595 const char *pfx = prefix;
e90fdc39
JS
596 if (!is_inside_work_tree()) {
597 const char *work_tree =
598 get_git_work_tree();
599 if (work_tree)
600 printf("%s\n", work_tree);
601 continue;
602 }
5f94c730
JH
603 while (pfx) {
604 pfx = strchr(pfx, '/');
605 if (pfx) {
606 pfx++;
607 printf("../");
608 }
609 }
610 putchar('\n');
611 continue;
612 }
a8783eeb
LT
613 if (!strcmp(arg, "--git-dir")) {
614 const char *gitdir = getenv(GIT_DIR_ENVIRONMENT);
615 static char cwd[PATH_MAX];
616 if (gitdir) {
617 puts(gitdir);
618 continue;
619 }
620 if (!prefix) {
621 puts(".git");
622 continue;
623 }
624 if (!getcwd(cwd, PATH_MAX))
0721c314 625 die_errno("unable to get current working directory");
a8783eeb
LT
626 printf("%s/.git\n", cwd);
627 continue;
628 }
6d9ba67b
JS
629 if (!strcmp(arg, "--is-inside-git-dir")) {
630 printf("%s\n", is_inside_git_dir() ? "true"
631 : "false");
632 continue;
633 }
892c41b9
ML
634 if (!strcmp(arg, "--is-inside-work-tree")) {
635 printf("%s\n", is_inside_work_tree() ? "true"
636 : "false");
637 continue;
638 }
493c774e
ML
639 if (!strcmp(arg, "--is-bare-repository")) {
640 printf("%s\n", is_bare_repository() ? "true"
641 : "false");
642 continue;
643 }
cc44c765 644 if (!prefixcmp(arg, "--since=")) {
c1babb1d
LT
645 show_datestring("--max-age=", arg+8);
646 continue;
647 }
cc44c765 648 if (!prefixcmp(arg, "--after=")) {
c1babb1d
LT
649 show_datestring("--max-age=", arg+8);
650 continue;
651 }
cc44c765 652 if (!prefixcmp(arg, "--before=")) {
c1babb1d
LT
653 show_datestring("--min-age=", arg+9);
654 continue;
655 }
cc44c765 656 if (!prefixcmp(arg, "--until=")) {
c1babb1d
LT
657 show_datestring("--min-age=", arg+8);
658 continue;
659 }
9523a4c2 660 if (show_flag(arg) && verify)
b1b35969 661 die_no_single_rev(quiet);
178cb243
LT
662 continue;
663 }
4866ccf0
JH
664
665 /* Not a flag argument */
3dd4e732
SB
666 if (try_difference(arg))
667 continue;
2122f8b9
BS
668 if (try_parent_shorthands(arg))
669 continue;
dfd1b749
CC
670 name = arg;
671 type = NORMAL;
672 if (*arg == '^') {
673 name++;
674 type = REVERSED;
800644c5 675 }
dfd1b749
CC
676 if (!get_sha1(name, sha1)) {
677 if (verify)
678 revs_count++;
679 else
680 show_rev(type, sha1, name);
800644c5
LT
681 continue;
682 }
75ecfce3
CC
683 if (verify)
684 die_no_single_rev(quiet);
9ad0a933
LT
685 as_is = 1;
686 if (!show_file(arg))
687 continue;
e23d0b4a 688 verify_filename(prefix, arg);
023d66ed 689 }
dfd1b749
CC
690 if (verify) {
691 if (revs_count == 1) {
692 show_rev(type, sha1, name);
693 return 0;
694 } else if (revs_count == 0 && show_default())
695 return 0;
b1b35969 696 die_no_single_rev(quiet);
dfd1b749
CC
697 } else
698 show_default();
178cb243
LT
699 return 0;
700}