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