4 * Copyright (C) Linus Torvalds, 2005
6 #define USE_THE_INDEX_VARIABLE
12 #include "environment.h"
18 #include "object-name.h"
19 #include "parse-options.h"
23 #include "split-index.h"
24 #include "submodule.h"
25 #include "commit-reach.h"
32 static int filter
= ~0;
34 static const char *def
;
38 static int show_type
= NORMAL
;
40 #define SHOW_SYMBOLIC_ASIS 1
41 #define SHOW_SYMBOLIC_FULL 2
44 static int abbrev_ref
;
45 static int abbrev_ref_strict
;
48 static int stuck_long
;
49 static struct ref_exclusions ref_excludes
= REF_EXCLUSIONS_INIT
;
52 * Some arguments are relevant "revision" arguments,
53 * others are about output format or other details.
54 * This sorts it all out.
56 static int is_rev_argument(const char *arg
)
58 static const char *rev_args
[] = {
89 const char **p
= rev_args
;
91 /* accept -<digit>, like traditional "head" */
92 if ((*arg
== '-') && isdigit(arg
[1]))
96 const char *str
= *p
++;
101 if (!strcmp(arg
, str
) ||
102 (str
[len
-1] == '=' && !strncmp(arg
, str
, len
)))
107 /* Output argument as a string, either SQ or normal */
108 static void show(const char *arg
)
114 while ((ch
= *arg
++)) {
116 fputs("'\\'", stdout
);
126 /* Like show(), but with a negation prefix according to type */
127 static void show_with_type(int type
, const char *arg
)
129 if (type
!= show_type
)
134 /* Output a revision, only if filter allows it */
135 static void show_rev(int type
, const struct object_id
*oid
, const char *name
)
137 if (!(filter
& DO_REVS
))
141 if ((symbolic
|| abbrev_ref
) && name
) {
142 if (symbolic
== SHOW_SYMBOLIC_FULL
|| abbrev_ref
) {
143 struct object_id discard
;
146 switch (repo_dwim_ref(the_repository
, name
,
147 strlen(name
), &discard
, &full
,
151 * Not found -- not a ref. We could
152 * emit "name" here, but symbolic-full
153 * users are interested in finding the
154 * refs spelled in full, and they would
155 * need to filter non-refs if we did so.
161 full
= shorten_unambiguous_ref(full
,
165 show_with_type(type
, full
);
167 default: /* ambiguous */
168 error("refname '%s' is ambiguous", name
);
173 show_with_type(type
, name
);
178 repo_find_unique_abbrev(the_repository
, oid
, abbrev
));
180 show_with_type(type
, oid_to_hex(oid
));
183 /* Output a flag, only if filter allows it. */
184 static int show_flag(const char *arg
)
186 if (!(filter
& DO_FLAGS
))
188 if (filter
& (is_rev_argument(arg
) ? DO_REVS
: DO_NOREV
)) {
195 static int show_default(void)
200 struct object_id oid
;
203 if (!repo_get_oid(the_repository
, s
, &oid
)) {
204 show_rev(NORMAL
, &oid
, s
);
211 static int show_reference(const char *refname
, const struct object_id
*oid
,
212 int flag UNUSED
, void *cb_data UNUSED
)
214 if (ref_excluded(&ref_excludes
, refname
))
216 show_rev(NORMAL
, oid
, refname
);
220 static int anti_reference(const char *refname
, const struct object_id
*oid
,
221 int flag UNUSED
, void *cb_data UNUSED
)
223 show_rev(REVERSED
, oid
, refname
);
227 static int show_abbrev(const struct object_id
*oid
, void *cb_data
)
229 show_rev(NORMAL
, oid
, NULL
);
233 static void show_datestring(const char *flag
, const char *datestr
)
237 /* date handling requires both flags and revs */
238 if ((filter
& (DO_FLAGS
| DO_REVS
)) != (DO_FLAGS
| DO_REVS
))
240 buffer
= xstrfmt("%s%"PRItime
, flag
, approxidate(datestr
));
245 static int show_file(const char *arg
, int output_prefix
)
248 if ((filter
& (DO_NONFLAGS
|DO_NOREV
)) == (DO_NONFLAGS
|DO_NOREV
)) {
250 const char *prefix
= startup_info
->prefix
;
251 char *fname
= prefix_filename(prefix
, arg
);
261 static int try_difference(const char *arg
)
264 struct object_id start_oid
;
265 struct object_id end_oid
;
269 static const char head_by_default
[] = "HEAD";
271 if (!(dotdot
= strstr(arg
, "..")))
275 symmetric
= (*end
== '.');
281 end
= head_by_default
;
283 start
= head_by_default
;
285 if (start
== head_by_default
&& end
== head_by_default
&&
288 * Just ".."? That is not a range but the
289 * pathspec for the parent directory.
295 if (!repo_get_oid_committish(the_repository
, start
, &start_oid
) && !repo_get_oid_committish(the_repository
, end
, &end_oid
)) {
296 show_rev(NORMAL
, &end_oid
, end
);
297 show_rev(symmetric
? NORMAL
: REVERSED
, &start_oid
, start
);
299 struct commit_list
*exclude
;
300 struct commit
*a
, *b
;
301 a
= lookup_commit_reference(the_repository
, &start_oid
);
302 b
= lookup_commit_reference(the_repository
, &end_oid
);
307 exclude
= repo_get_merge_bases(the_repository
, a
, b
);
309 struct commit
*commit
= pop_commit(&exclude
);
310 show_rev(REVERSED
, &commit
->object
.oid
, NULL
);
320 static int try_parent_shorthands(const char *arg
)
323 struct object_id oid
;
324 struct commit
*commit
;
325 struct commit_list
*parents
;
328 int include_parents
= 0;
329 int exclude_parent
= 0;
331 if ((dotdot
= strstr(arg
, "^!"))) {
335 } else if ((dotdot
= strstr(arg
, "^@"))) {
339 } else if ((dotdot
= strstr(arg
, "^-"))) {
345 exclude_parent
= strtoul(dotdot
+ 2, &end
, 10);
346 if (*end
!= '\0' || !exclude_parent
)
353 if (repo_get_oid_committish(the_repository
, arg
, &oid
) ||
354 !(commit
= lookup_commit_reference(the_repository
, &oid
))) {
359 if (exclude_parent
&&
360 exclude_parent
> commit_list_count(commit
->parents
)) {
366 show_rev(NORMAL
, &oid
, arg
);
367 for (parents
= commit
->parents
, parent_number
= 1;
369 parents
= parents
->next
, parent_number
++) {
372 if (exclude_parent
&& parent_number
!= exclude_parent
)
376 name
= xstrfmt("%s^%d", arg
, parent_number
);
377 show_rev(include_parents
? NORMAL
: REVERSED
,
378 &parents
->item
->object
.oid
, name
);
386 static int parseopt_dump(const struct option
*o
, const char *arg
, int unset
)
388 struct strbuf
*parsed
= o
->value
;
390 strbuf_addf(parsed
, " --no-%s", o
->long_name
);
391 else if (o
->short_name
&& (o
->long_name
== NULL
|| !stuck_long
))
392 strbuf_addf(parsed
, " -%c", o
->short_name
);
394 strbuf_addf(parsed
, " --%s", o
->long_name
);
397 strbuf_addch(parsed
, ' ');
398 else if (o
->long_name
)
399 strbuf_addch(parsed
, '=');
400 sq_quote_buf(parsed
, arg
);
405 static const char *skipspaces(const char *s
)
412 static char *findspace(const char *s
)
420 static int cmd_parseopt(int argc
, const char **argv
, const char *prefix
)
422 static int keep_dashdash
= 0, stop_at_non_option
= 0;
423 static char const * const parseopt_usage
[] = {
424 N_("git rev-parse --parseopt [<options>] -- [<args>...]"),
427 static struct option parseopt_opts
[] = {
428 OPT_BOOL(0, "keep-dashdash", &keep_dashdash
,
429 N_("keep the `--` passed as an arg")),
430 OPT_BOOL(0, "stop-at-non-option", &stop_at_non_option
,
431 N_("stop parsing after the "
432 "first non-option argument")),
433 OPT_BOOL(0, "stuck-long", &stuck_long
,
434 N_("output in stuck long form")),
437 static const char * const flag_chars
= "*=?!";
439 struct strbuf sb
= STRBUF_INIT
, parsed
= STRBUF_INIT
;
440 const char **usage
= NULL
;
441 struct option
*opts
= NULL
;
442 int onb
= 0, osz
= 0, unb
= 0, usz
= 0;
444 strbuf_addstr(&parsed
, "set --");
445 argc
= parse_options(argc
, argv
, prefix
, parseopt_opts
, parseopt_usage
,
446 PARSE_OPT_KEEP_DASHDASH
);
447 if (argc
< 1 || strcmp(argv
[0], "--"))
448 usage_with_options(parseopt_usage
, parseopt_opts
);
450 /* get the usage up to the first line with a -- on it */
452 if (strbuf_getline(&sb
, stdin
) == EOF
)
453 die(_("premature end of input"));
454 ALLOC_GROW(usage
, unb
+ 1, usz
);
455 if (!strcmp("--", sb
.buf
)) {
457 die(_("no usage string given before the `--' separator"));
461 usage
[unb
++] = strbuf_detach(&sb
, NULL
);
464 /* parse: (<short>|<short>,<long>|<long>)[*=?!]*<arghint>? SP+ <help> */
465 while (strbuf_getline(&sb
, stdin
) != EOF
) {
473 ALLOC_GROW(opts
, onb
+ 1, osz
);
474 memset(opts
+ onb
, 0, sizeof(opts
[onb
]));
477 help
= findspace(sb
.buf
);
478 if (!help
|| sb
.buf
== help
) {
479 o
->type
= OPTION_GROUP
;
480 o
->help
= xstrdup(skipspaces(sb
.buf
));
486 o
->type
= OPTION_CALLBACK
;
487 o
->help
= xstrdup(skipspaces(help
+1));
489 o
->flags
= PARSE_OPT_NOARG
;
490 o
->callback
= &parseopt_dump
;
493 s
= strpbrk(sb
.buf
, flag_chars
);
498 die(_("missing opt-spec before option flags"));
500 if (s
- sb
.buf
== 1) /* short option only */
501 o
->short_name
= *sb
.buf
;
502 else if (sb
.buf
[1] != ',') /* long option only */
503 o
->long_name
= xmemdupz(sb
.buf
, s
- sb
.buf
);
505 o
->short_name
= *sb
.buf
;
506 o
->long_name
= xmemdupz(sb
.buf
+ 2, s
- sb
.buf
- 2);
513 o
->flags
&= ~PARSE_OPT_NOARG
;
516 o
->flags
&= ~PARSE_OPT_NOARG
;
517 o
->flags
|= PARSE_OPT_OPTARG
;
520 o
->flags
|= PARSE_OPT_NONEG
;
523 o
->flags
|= PARSE_OPT_HIDDEN
;
531 o
->argh
= xmemdupz(s
, help
- s
);
535 /* put an OPT_END() */
536 ALLOC_GROW(opts
, onb
+ 1, osz
);
537 memset(opts
+ onb
, 0, sizeof(opts
[onb
]));
538 argc
= parse_options(argc
, argv
, prefix
, opts
, usage
,
539 (keep_dashdash
? PARSE_OPT_KEEP_DASHDASH
: 0) |
540 (stop_at_non_option
? PARSE_OPT_STOP_AT_NON_OPTION
: 0) |
541 PARSE_OPT_SHELL_EVAL
);
543 strbuf_addstr(&parsed
, " --");
544 sq_quote_argv(&parsed
, argv
);
546 strbuf_release(&parsed
);
550 static int cmd_sq_quote(int argc
, const char **argv
)
552 struct strbuf buf
= STRBUF_INIT
;
555 sq_quote_argv(&buf
, argv
);
556 printf("%s\n", buf
.buf
);
557 strbuf_release(&buf
);
562 static void die_no_single_rev(int quiet
)
567 die(_("Needed a single revision"));
570 static const char builtin_rev_parse_usage
[] =
571 N_("git rev-parse --parseopt [<options>] -- [<args>...]\n"
572 " or: git rev-parse --sq-quote [<arg>...]\n"
573 " or: git rev-parse [<options>] [<arg>...]\n"
575 "Run \"git rev-parse --parseopt -h\" for more information on the first usage.");
578 * Parse "opt" or "opt=<value>", setting value respectively to either
579 * NULL or the string after "=".
581 static int opt_with_value(const char *arg
, const char *opt
, const char **value
)
583 if (skip_prefix(arg
, opt
, &arg
)) {
596 static void handle_ref_opt(const char *pattern
, const char *prefix
)
599 for_each_glob_ref_in(show_reference
, pattern
, prefix
, NULL
);
601 for_each_ref_in(prefix
, show_reference
, NULL
);
602 clear_ref_exclusions(&ref_excludes
);
606 /* We would like a relative path. */
608 /* We would like a canonical absolute path. */
610 /* We would like the default behavior. */
615 /* Our default is a relative path. */
617 /* Our default is a relative path if there's a shared root. */
618 DEFAULT_RELATIVE_IF_SHARED
,
619 /* Our default is a canonical absolute path. */
621 /* Our default is not to modify the item. */
625 static void print_path(const char *path
, const char *prefix
, enum format_type format
, enum default_type def
)
629 * We don't ever produce a relative path if prefix is NULL, so set the
630 * prefix to the current directory so that we can produce a relative
631 * path whenever possible. If we're using RELATIVE_IF_SHARED mode, then
632 * we want an absolute path unless the two share a common prefix, so don't
633 * set it in that case, since doing so causes a relative path to always
634 * be produced if possible.
636 if (!prefix
&& (format
!= FORMAT_DEFAULT
|| def
!= DEFAULT_RELATIVE_IF_SHARED
))
637 prefix
= cwd
= xgetcwd();
638 if (format
== FORMAT_DEFAULT
&& def
== DEFAULT_UNMODIFIED
) {
640 } else if (format
== FORMAT_RELATIVE
||
641 (format
== FORMAT_DEFAULT
&& def
== DEFAULT_RELATIVE
)) {
643 * In order for relative_path to work as expected, we need to
644 * make sure that both paths are absolute paths. If we don't,
645 * we can end up with an unexpected absolute path that the user
648 struct strbuf buf
= STRBUF_INIT
, realbuf
= STRBUF_INIT
, prefixbuf
= STRBUF_INIT
;
649 if (!is_absolute_path(path
)) {
650 strbuf_realpath_forgiving(&realbuf
, path
, 1);
653 if (!is_absolute_path(prefix
)) {
654 strbuf_realpath_forgiving(&prefixbuf
, prefix
, 1);
655 prefix
= prefixbuf
.buf
;
657 puts(relative_path(path
, prefix
, &buf
));
658 strbuf_release(&buf
);
659 strbuf_release(&realbuf
);
660 strbuf_release(&prefixbuf
);
661 } else if (format
== FORMAT_DEFAULT
&& def
== DEFAULT_RELATIVE_IF_SHARED
) {
662 struct strbuf buf
= STRBUF_INIT
;
663 puts(relative_path(path
, prefix
, &buf
));
664 strbuf_release(&buf
);
666 struct strbuf buf
= STRBUF_INIT
;
667 strbuf_realpath_forgiving(&buf
, path
, 1);
669 strbuf_release(&buf
);
674 int cmd_rev_parse(int argc
, const char **argv
, const char *prefix
)
676 int i
, as_is
= 0, verify
= 0, quiet
= 0, revs_count
= 0, type
= 0;
677 int did_repo_setup
= 0;
678 int has_dashdash
= 0;
679 int output_prefix
= 0;
680 struct object_id oid
;
681 unsigned int flags
= 0;
682 const char *name
= NULL
;
683 struct object_context unused
;
684 struct strbuf buf
= STRBUF_INIT
;
685 const int hexsz
= the_hash_algo
->hexsz
;
686 int seen_end_of_options
= 0;
687 enum format_type format
= FORMAT_DEFAULT
;
689 if (argc
> 1 && !strcmp("--parseopt", argv
[1]))
690 return cmd_parseopt(argc
- 1, argv
+ 1, prefix
);
692 if (argc
> 1 && !strcmp("--sq-quote", argv
[1]))
693 return cmd_sq_quote(argc
- 2, argv
+ 2);
695 if (argc
> 1 && !strcmp("-h", argv
[1]))
696 usage(builtin_rev_parse_usage
);
698 for (i
= 1; i
< argc
; i
++) {
699 if (!strcmp(argv
[i
], "--")) {
705 /* No options; just report on whether we're in a git repo or not. */
707 setup_git_directory();
708 git_config(git_default_config
, NULL
);
712 for (i
= 1; i
< argc
; i
++) {
713 const char *arg
= argv
[i
];
716 if (show_file(arg
, output_prefix
) && as_is
< 2)
717 verify_filename(prefix
, arg
, 0);
721 if (!seen_end_of_options
) {
722 if (!strcmp(arg
, "--local-env-vars")) {
724 for (i
= 0; local_repo_env
[i
]; i
++)
725 printf("%s\n", local_repo_env
[i
]);
728 if (!strcmp(arg
, "--resolve-git-dir")) {
729 const char *gitdir
= argv
[++i
];
731 die(_("--resolve-git-dir requires an argument"));
732 gitdir
= resolve_gitdir(gitdir
);
734 die(_("not a gitdir '%s'"), argv
[i
]);
740 /* The rest of the options require a git repository. */
741 if (!did_repo_setup
) {
742 prefix
= setup_git_directory();
743 git_config(git_default_config
, NULL
);
746 prepare_repo_settings(the_repository
);
747 the_repository
->settings
.command_requires_full_index
= 0;
750 if (!strcmp(arg
, "--")) {
752 /* Pass on the "--" if we show anything but files.. */
753 if (filter
& (DO_FLAGS
| DO_REVS
))
758 if (!seen_end_of_options
&& *arg
== '-') {
759 if (!strcmp(arg
, "--git-path")) {
761 die(_("--git-path requires an argument"));
763 print_path(git_path("%s", argv
[i
+ 1]), prefix
,
765 DEFAULT_RELATIVE_IF_SHARED
);
769 if (!strcmp(arg
,"-n")) {
771 die(_("-n requires an argument"));
772 if ((filter
& DO_FLAGS
) && (filter
& DO_REVS
)) {
778 if (starts_with(arg
, "-n")) {
779 if ((filter
& DO_FLAGS
) && (filter
& DO_REVS
))
783 if (opt_with_value(arg
, "--path-format", &arg
)) {
785 die(_("--path-format requires an argument"));
786 if (!strcmp(arg
, "absolute")) {
787 format
= FORMAT_CANONICAL
;
788 } else if (!strcmp(arg
, "relative")) {
789 format
= FORMAT_RELATIVE
;
791 die(_("unknown argument to --path-format: %s"), arg
);
795 if (!strcmp(arg
, "--default")) {
798 die(_("--default requires an argument"));
801 if (!strcmp(arg
, "--prefix")) {
804 die(_("--prefix requires an argument"));
805 startup_info
->prefix
= prefix
;
809 if (!strcmp(arg
, "--revs-only")) {
813 if (!strcmp(arg
, "--no-revs")) {
817 if (!strcmp(arg
, "--flags")) {
818 filter
&= ~DO_NONFLAGS
;
821 if (!strcmp(arg
, "--no-flags")) {
825 if (!strcmp(arg
, "--verify")) {
826 filter
&= ~(DO_FLAGS
|DO_NOREV
);
830 if (!strcmp(arg
, "--quiet") || !strcmp(arg
, "-q")) {
832 flags
|= GET_OID_QUIETLY
;
835 if (opt_with_value(arg
, "--short", &arg
)) {
836 filter
&= ~(DO_FLAGS
|DO_NOREV
);
838 abbrev
= DEFAULT_ABBREV
;
841 abbrev
= strtoul(arg
, NULL
, 10);
842 if (abbrev
< MINIMUM_ABBREV
)
843 abbrev
= MINIMUM_ABBREV
;
844 else if (hexsz
<= abbrev
)
848 if (!strcmp(arg
, "--sq")) {
852 if (!strcmp(arg
, "--not")) {
853 show_type
^= REVERSED
;
856 if (!strcmp(arg
, "--symbolic")) {
857 symbolic
= SHOW_SYMBOLIC_ASIS
;
860 if (!strcmp(arg
, "--symbolic-full-name")) {
861 symbolic
= SHOW_SYMBOLIC_FULL
;
864 if (opt_with_value(arg
, "--abbrev-ref", &arg
)) {
866 abbrev_ref_strict
= warn_ambiguous_refs
;
868 if (!strcmp(arg
, "strict"))
869 abbrev_ref_strict
= 1;
870 else if (!strcmp(arg
, "loose"))
871 abbrev_ref_strict
= 0;
873 die(_("unknown mode for --abbrev-ref: %s"),
878 if (!strcmp(arg
, "--all")) {
879 for_each_ref(show_reference
, NULL
);
880 clear_ref_exclusions(&ref_excludes
);
883 if (skip_prefix(arg
, "--disambiguate=", &arg
)) {
884 repo_for_each_abbrev(the_repository
, arg
,
888 if (!strcmp(arg
, "--bisect")) {
889 for_each_fullref_in("refs/bisect/bad", show_reference
, NULL
);
890 for_each_fullref_in("refs/bisect/good", anti_reference
, NULL
);
893 if (opt_with_value(arg
, "--branches", &arg
)) {
894 if (ref_excludes
.hidden_refs_configured
)
895 return error(_("--exclude-hidden cannot be used together with --branches"));
896 handle_ref_opt(arg
, "refs/heads/");
899 if (opt_with_value(arg
, "--tags", &arg
)) {
900 if (ref_excludes
.hidden_refs_configured
)
901 return error(_("--exclude-hidden cannot be used together with --tags"));
902 handle_ref_opt(arg
, "refs/tags/");
905 if (skip_prefix(arg
, "--glob=", &arg
)) {
906 handle_ref_opt(arg
, NULL
);
909 if (opt_with_value(arg
, "--remotes", &arg
)) {
910 if (ref_excludes
.hidden_refs_configured
)
911 return error(_("--exclude-hidden cannot be used together with --remotes"));
912 handle_ref_opt(arg
, "refs/remotes/");
915 if (skip_prefix(arg
, "--exclude=", &arg
)) {
916 add_ref_exclusion(&ref_excludes
, arg
);
919 if (skip_prefix(arg
, "--exclude-hidden=", &arg
)) {
920 exclude_hidden_refs(&ref_excludes
, arg
);
923 if (!strcmp(arg
, "--show-toplevel")) {
924 const char *work_tree
= get_git_work_tree();
926 print_path(work_tree
, prefix
, format
, DEFAULT_UNMODIFIED
);
928 die(_("this operation must be run in a work tree"));
931 if (!strcmp(arg
, "--show-superproject-working-tree")) {
932 struct strbuf superproject
= STRBUF_INIT
;
933 if (get_superproject_working_tree(&superproject
))
934 print_path(superproject
.buf
, prefix
, format
, DEFAULT_UNMODIFIED
);
935 strbuf_release(&superproject
);
938 if (!strcmp(arg
, "--show-prefix")) {
945 if (!strcmp(arg
, "--show-cdup")) {
946 const char *pfx
= prefix
;
947 if (!is_inside_work_tree()) {
948 const char *work_tree
=
951 printf("%s\n", work_tree
);
955 pfx
= strchr(pfx
, '/');
964 if (!strcmp(arg
, "--git-dir") ||
965 !strcmp(arg
, "--absolute-git-dir")) {
966 const char *gitdir
= getenv(GIT_DIR_ENVIRONMENT
);
969 enum format_type wanted
= format
;
970 if (arg
[2] == 'g') { /* --git-dir */
972 print_path(gitdir
, prefix
, format
, DEFAULT_UNMODIFIED
);
976 print_path(".git", prefix
, format
, DEFAULT_UNMODIFIED
);
979 } else { /* --absolute-git-dir */
980 wanted
= FORMAT_CANONICAL
;
981 if (!gitdir
&& !prefix
)
984 struct strbuf realpath
= STRBUF_INIT
;
985 strbuf_realpath(&realpath
, gitdir
, 1);
987 strbuf_release(&realpath
);
994 strbuf_addf(&buf
, "%s%s.git", cwd
, len
&& cwd
[len
-1] != '/' ? "/" : "");
996 print_path(buf
.buf
, prefix
, wanted
, DEFAULT_CANONICAL
);
999 if (!strcmp(arg
, "--git-common-dir")) {
1000 print_path(get_git_common_dir(), prefix
, format
, DEFAULT_RELATIVE_IF_SHARED
);
1003 if (!strcmp(arg
, "--is-inside-git-dir")) {
1004 printf("%s\n", is_inside_git_dir() ? "true"
1008 if (!strcmp(arg
, "--is-inside-work-tree")) {
1009 printf("%s\n", is_inside_work_tree() ? "true"
1013 if (!strcmp(arg
, "--is-bare-repository")) {
1014 printf("%s\n", is_bare_repository() ? "true"
1018 if (!strcmp(arg
, "--is-shallow-repository")) {
1020 is_repository_shallow(the_repository
) ? "true"
1024 if (!strcmp(arg
, "--shared-index-path")) {
1025 if (repo_read_index(the_repository
) < 0)
1026 die(_("Could not read the index"));
1027 if (the_index
.split_index
) {
1028 const struct object_id
*oid
= &the_index
.split_index
->base_oid
;
1029 const char *path
= git_path("sharedindex.%s", oid_to_hex(oid
));
1030 print_path(path
, prefix
, format
, DEFAULT_RELATIVE
);
1034 if (skip_prefix(arg
, "--since=", &arg
)) {
1035 show_datestring("--max-age=", arg
);
1038 if (skip_prefix(arg
, "--after=", &arg
)) {
1039 show_datestring("--max-age=", arg
);
1042 if (skip_prefix(arg
, "--before=", &arg
)) {
1043 show_datestring("--min-age=", arg
);
1046 if (skip_prefix(arg
, "--until=", &arg
)) {
1047 show_datestring("--min-age=", arg
);
1050 if (opt_with_value(arg
, "--show-object-format", &arg
)) {
1051 const char *val
= arg
? arg
: "storage";
1053 if (strcmp(val
, "storage") &&
1054 strcmp(val
, "input") &&
1055 strcmp(val
, "output"))
1056 die(_("unknown mode for --show-object-format: %s"),
1058 puts(the_hash_algo
->name
);
1061 if (!strcmp(arg
, "--end-of-options")) {
1062 seen_end_of_options
= 1;
1063 if (filter
& (DO_FLAGS
| DO_REVS
))
1067 if (show_flag(arg
) && verify
)
1068 die_no_single_rev(quiet
);
1072 /* Not a flag argument */
1073 if (try_difference(arg
))
1075 if (try_parent_shorthands(arg
))
1083 if (!get_oid_with_context(the_repository
, name
,
1084 flags
, &oid
, &unused
)) {
1088 show_rev(type
, &oid
, name
);
1092 die_no_single_rev(quiet
);
1094 die(_("bad revision '%s'"), arg
);
1096 if (!show_file(arg
, output_prefix
))
1098 verify_filename(prefix
, arg
, 1);
1100 strbuf_release(&buf
);
1102 if (revs_count
== 1) {
1103 show_rev(type
, &oid
, name
);
1105 } else if (revs_count
== 0 && show_default())
1107 die_no_single_rev(quiet
);