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"
21 #include "read-cache-ll.h"
24 #include "split-index.h"
25 #include "submodule.h"
26 #include "commit-reach.h"
33 static int filter
= ~0;
35 static const char *def
;
39 static int show_type
= NORMAL
;
41 #define SHOW_SYMBOLIC_ASIS 1
42 #define SHOW_SYMBOLIC_FULL 2
45 static int abbrev_ref
;
46 static int abbrev_ref_strict
;
49 static int stuck_long
;
50 static struct ref_exclusions ref_excludes
= REF_EXCLUSIONS_INIT
;
53 * Some arguments are relevant "revision" arguments,
54 * others are about output format or other details.
55 * This sorts it all out.
57 static int is_rev_argument(const char *arg
)
59 static const char *rev_args
[] = {
90 const char **p
= rev_args
;
92 /* accept -<digit>, like traditional "head" */
93 if ((*arg
== '-') && isdigit(arg
[1]))
97 const char *str
= *p
++;
102 if (!strcmp(arg
, str
) ||
103 (str
[len
-1] == '=' && !strncmp(arg
, str
, len
)))
108 /* Output argument as a string, either SQ or normal */
109 static void show(const char *arg
)
115 while ((ch
= *arg
++)) {
117 fputs("'\\'", stdout
);
127 /* Like show(), but with a negation prefix according to type */
128 static void show_with_type(int type
, const char *arg
)
130 if (type
!= show_type
)
135 /* Output a revision, only if filter allows it */
136 static void show_rev(int type
, const struct object_id
*oid
, const char *name
)
138 if (!(filter
& DO_REVS
))
142 if ((symbolic
|| abbrev_ref
) && name
) {
143 if (symbolic
== SHOW_SYMBOLIC_FULL
|| abbrev_ref
) {
144 struct object_id discard
;
147 switch (repo_dwim_ref(the_repository
, name
,
148 strlen(name
), &discard
, &full
,
152 * Not found -- not a ref. We could
153 * emit "name" here, but symbolic-full
154 * users are interested in finding the
155 * refs spelled in full, and they would
156 * need to filter non-refs if we did so.
161 full
= shorten_unambiguous_ref(full
,
163 show_with_type(type
, full
);
165 default: /* ambiguous */
166 error("refname '%s' is ambiguous", name
);
171 show_with_type(type
, name
);
176 repo_find_unique_abbrev(the_repository
, oid
, abbrev
));
178 show_with_type(type
, oid_to_hex(oid
));
181 /* Output a flag, only if filter allows it. */
182 static int show_flag(const char *arg
)
184 if (!(filter
& DO_FLAGS
))
186 if (filter
& (is_rev_argument(arg
) ? DO_REVS
: DO_NOREV
)) {
193 static int show_default(void)
198 struct object_id oid
;
201 if (!repo_get_oid(the_repository
, s
, &oid
)) {
202 show_rev(NORMAL
, &oid
, s
);
209 static int show_reference(const char *refname
, const struct object_id
*oid
,
210 int flag UNUSED
, void *cb_data UNUSED
)
212 if (ref_excluded(&ref_excludes
, refname
))
214 show_rev(NORMAL
, oid
, refname
);
218 static int anti_reference(const char *refname
, const struct object_id
*oid
,
219 int flag UNUSED
, void *cb_data UNUSED
)
221 show_rev(REVERSED
, oid
, refname
);
225 static int show_abbrev(const struct object_id
*oid
, void *cb_data
)
227 show_rev(NORMAL
, oid
, NULL
);
231 static void show_datestring(const char *flag
, const char *datestr
)
235 /* date handling requires both flags and revs */
236 if ((filter
& (DO_FLAGS
| DO_REVS
)) != (DO_FLAGS
| DO_REVS
))
238 buffer
= xstrfmt("%s%"PRItime
, flag
, approxidate(datestr
));
243 static int show_file(const char *arg
, int output_prefix
)
246 if ((filter
& (DO_NONFLAGS
|DO_NOREV
)) == (DO_NONFLAGS
|DO_NOREV
)) {
248 const char *prefix
= startup_info
->prefix
;
249 char *fname
= prefix_filename(prefix
, arg
);
259 static int try_difference(const char *arg
)
262 struct object_id start_oid
;
263 struct object_id end_oid
;
267 static const char head_by_default
[] = "HEAD";
269 if (!(dotdot
= strstr(arg
, "..")))
273 symmetric
= (*end
== '.');
279 end
= head_by_default
;
281 start
= head_by_default
;
283 if (start
== head_by_default
&& end
== head_by_default
&&
286 * Just ".."? That is not a range but the
287 * pathspec for the parent directory.
293 if (!repo_get_oid_committish(the_repository
, start
, &start_oid
) && !repo_get_oid_committish(the_repository
, end
, &end_oid
)) {
294 show_rev(NORMAL
, &end_oid
, end
);
295 show_rev(symmetric
? NORMAL
: REVERSED
, &start_oid
, start
);
297 struct commit_list
*exclude
;
298 struct commit
*a
, *b
;
299 a
= lookup_commit_reference(the_repository
, &start_oid
);
300 b
= lookup_commit_reference(the_repository
, &end_oid
);
305 exclude
= repo_get_merge_bases(the_repository
, a
, b
);
307 struct commit
*commit
= pop_commit(&exclude
);
308 show_rev(REVERSED
, &commit
->object
.oid
, NULL
);
318 static int try_parent_shorthands(const char *arg
)
321 struct object_id oid
;
322 struct commit
*commit
;
323 struct commit_list
*parents
;
326 int include_parents
= 0;
327 int exclude_parent
= 0;
329 if ((dotdot
= strstr(arg
, "^!"))) {
333 } else if ((dotdot
= strstr(arg
, "^@"))) {
337 } else if ((dotdot
= strstr(arg
, "^-"))) {
343 exclude_parent
= strtoul(dotdot
+ 2, &end
, 10);
344 if (*end
!= '\0' || !exclude_parent
)
351 if (repo_get_oid_committish(the_repository
, arg
, &oid
) ||
352 !(commit
= lookup_commit_reference(the_repository
, &oid
))) {
357 if (exclude_parent
&&
358 exclude_parent
> commit_list_count(commit
->parents
)) {
364 show_rev(NORMAL
, &oid
, arg
);
365 for (parents
= commit
->parents
, parent_number
= 1;
367 parents
= parents
->next
, parent_number
++) {
370 if (exclude_parent
&& parent_number
!= exclude_parent
)
374 name
= xstrfmt("%s^%d", arg
, parent_number
);
375 show_rev(include_parents
? NORMAL
: REVERSED
,
376 &parents
->item
->object
.oid
, name
);
384 static int parseopt_dump(const struct option
*o
, const char *arg
, int unset
)
386 struct strbuf
*parsed
= o
->value
;
388 strbuf_addf(parsed
, " --no-%s", o
->long_name
);
389 else if (o
->short_name
&& (o
->long_name
== NULL
|| !stuck_long
))
390 strbuf_addf(parsed
, " -%c", o
->short_name
);
392 strbuf_addf(parsed
, " --%s", o
->long_name
);
395 strbuf_addch(parsed
, ' ');
396 else if (o
->long_name
)
397 strbuf_addch(parsed
, '=');
398 sq_quote_buf(parsed
, arg
);
403 static const char *skipspaces(const char *s
)
410 static char *findspace(const char *s
)
418 static int cmd_parseopt(int argc
, const char **argv
, const char *prefix
)
420 static int keep_dashdash
= 0, stop_at_non_option
= 0;
421 static char const * const parseopt_usage
[] = {
422 N_("git rev-parse --parseopt [<options>] -- [<args>...]"),
425 static struct option parseopt_opts
[] = {
426 OPT_BOOL(0, "keep-dashdash", &keep_dashdash
,
427 N_("keep the `--` passed as an arg")),
428 OPT_BOOL(0, "stop-at-non-option", &stop_at_non_option
,
429 N_("stop parsing after the "
430 "first non-option argument")),
431 OPT_BOOL(0, "stuck-long", &stuck_long
,
432 N_("output in stuck long form")),
435 static const char * const flag_chars
= "*=?!";
437 struct strbuf sb
= STRBUF_INIT
, parsed
= STRBUF_INIT
;
438 const char **usage
= NULL
;
439 struct option
*opts
= NULL
;
440 int onb
= 0, osz
= 0, unb
= 0, usz
= 0;
442 strbuf_addstr(&parsed
, "set --");
443 argc
= parse_options(argc
, argv
, prefix
, parseopt_opts
, parseopt_usage
,
444 PARSE_OPT_KEEP_DASHDASH
);
445 if (argc
< 1 || strcmp(argv
[0], "--"))
446 usage_with_options(parseopt_usage
, parseopt_opts
);
448 /* get the usage up to the first line with a -- on it */
450 if (strbuf_getline(&sb
, stdin
) == EOF
)
451 die(_("premature end of input"));
452 ALLOC_GROW(usage
, unb
+ 1, usz
);
453 if (!strcmp("--", sb
.buf
)) {
455 die(_("no usage string given before the `--' separator"));
459 usage
[unb
++] = strbuf_detach(&sb
, NULL
);
462 /* parse: (<short>|<short>,<long>|<long>)[*=?!]*<arghint>? SP+ <help> */
463 while (strbuf_getline(&sb
, stdin
) != EOF
) {
471 ALLOC_GROW(opts
, onb
+ 1, osz
);
472 memset(opts
+ onb
, 0, sizeof(opts
[onb
]));
475 help
= findspace(sb
.buf
);
476 if (!help
|| sb
.buf
== help
) {
477 o
->type
= OPTION_GROUP
;
478 o
->help
= xstrdup(skipspaces(sb
.buf
));
484 o
->type
= OPTION_CALLBACK
;
485 o
->help
= xstrdup(skipspaces(help
+1));
487 o
->flags
= PARSE_OPT_NOARG
;
488 o
->callback
= &parseopt_dump
;
491 s
= strpbrk(sb
.buf
, flag_chars
);
496 die(_("missing opt-spec before option flags"));
498 if (s
- sb
.buf
== 1) /* short option only */
499 o
->short_name
= *sb
.buf
;
500 else if (sb
.buf
[1] != ',') /* long option only */
501 o
->long_name
= xmemdupz(sb
.buf
, s
- sb
.buf
);
503 o
->short_name
= *sb
.buf
;
504 o
->long_name
= xmemdupz(sb
.buf
+ 2, s
- sb
.buf
- 2);
511 o
->flags
&= ~PARSE_OPT_NOARG
;
514 o
->flags
&= ~PARSE_OPT_NOARG
;
515 o
->flags
|= PARSE_OPT_OPTARG
;
518 o
->flags
|= PARSE_OPT_NONEG
;
521 o
->flags
|= PARSE_OPT_HIDDEN
;
529 o
->argh
= xmemdupz(s
, help
- s
);
533 /* put an OPT_END() */
534 ALLOC_GROW(opts
, onb
+ 1, osz
);
535 memset(opts
+ onb
, 0, sizeof(opts
[onb
]));
536 argc
= parse_options(argc
, argv
, prefix
, opts
, usage
,
537 (keep_dashdash
? PARSE_OPT_KEEP_DASHDASH
: 0) |
538 (stop_at_non_option
? PARSE_OPT_STOP_AT_NON_OPTION
: 0) |
539 PARSE_OPT_SHELL_EVAL
);
541 strbuf_addstr(&parsed
, " --");
542 sq_quote_argv(&parsed
, argv
);
544 strbuf_release(&parsed
);
548 static int cmd_sq_quote(int argc
, const char **argv
)
550 struct strbuf buf
= STRBUF_INIT
;
553 sq_quote_argv(&buf
, argv
);
554 printf("%s\n", buf
.buf
);
555 strbuf_release(&buf
);
560 static void die_no_single_rev(int quiet
)
565 die(_("Needed a single revision"));
568 static const char builtin_rev_parse_usage
[] =
569 N_("git rev-parse --parseopt [<options>] -- [<args>...]\n"
570 " or: git rev-parse --sq-quote [<arg>...]\n"
571 " or: git rev-parse [<options>] [<arg>...]\n"
573 "Run \"git rev-parse --parseopt -h\" for more information on the first usage.");
576 * Parse "opt" or "opt=<value>", setting value respectively to either
577 * NULL or the string after "=".
579 static int opt_with_value(const char *arg
, const char *opt
, const char **value
)
581 if (skip_prefix(arg
, opt
, &arg
)) {
594 static void handle_ref_opt(const char *pattern
, const char *prefix
)
597 for_each_glob_ref_in(show_reference
, pattern
, prefix
, NULL
);
599 for_each_ref_in(prefix
, show_reference
, NULL
);
600 clear_ref_exclusions(&ref_excludes
);
604 /* We would like a relative path. */
606 /* We would like a canonical absolute path. */
608 /* We would like the default behavior. */
613 /* Our default is a relative path. */
615 /* Our default is a relative path if there's a shared root. */
616 DEFAULT_RELATIVE_IF_SHARED
,
617 /* Our default is a canonical absolute path. */
619 /* Our default is not to modify the item. */
623 static void print_path(const char *path
, const char *prefix
, enum format_type format
, enum default_type def
)
627 * We don't ever produce a relative path if prefix is NULL, so set the
628 * prefix to the current directory so that we can produce a relative
629 * path whenever possible. If we're using RELATIVE_IF_SHARED mode, then
630 * we want an absolute path unless the two share a common prefix, so don't
631 * set it in that case, since doing so causes a relative path to always
632 * be produced if possible.
634 if (!prefix
&& (format
!= FORMAT_DEFAULT
|| def
!= DEFAULT_RELATIVE_IF_SHARED
))
635 prefix
= cwd
= xgetcwd();
636 if (format
== FORMAT_DEFAULT
&& def
== DEFAULT_UNMODIFIED
) {
638 } else if (format
== FORMAT_RELATIVE
||
639 (format
== FORMAT_DEFAULT
&& def
== DEFAULT_RELATIVE
)) {
641 * In order for relative_path to work as expected, we need to
642 * make sure that both paths are absolute paths. If we don't,
643 * we can end up with an unexpected absolute path that the user
646 struct strbuf buf
= STRBUF_INIT
, realbuf
= STRBUF_INIT
, prefixbuf
= STRBUF_INIT
;
647 if (!is_absolute_path(path
)) {
648 strbuf_realpath_forgiving(&realbuf
, path
, 1);
651 if (!is_absolute_path(prefix
)) {
652 strbuf_realpath_forgiving(&prefixbuf
, prefix
, 1);
653 prefix
= prefixbuf
.buf
;
655 puts(relative_path(path
, prefix
, &buf
));
656 strbuf_release(&buf
);
657 strbuf_release(&realbuf
);
658 strbuf_release(&prefixbuf
);
659 } else if (format
== FORMAT_DEFAULT
&& def
== DEFAULT_RELATIVE_IF_SHARED
) {
660 struct strbuf buf
= STRBUF_INIT
;
661 puts(relative_path(path
, prefix
, &buf
));
662 strbuf_release(&buf
);
664 struct strbuf buf
= STRBUF_INIT
;
665 strbuf_realpath_forgiving(&buf
, path
, 1);
667 strbuf_release(&buf
);
672 int cmd_rev_parse(int argc
, const char **argv
, const char *prefix
)
674 int i
, as_is
= 0, verify
= 0, quiet
= 0, revs_count
= 0, type
= 0;
675 int did_repo_setup
= 0;
676 int has_dashdash
= 0;
677 int output_prefix
= 0;
678 struct object_id oid
;
679 unsigned int flags
= 0;
680 const char *name
= NULL
;
681 struct object_context unused
;
682 struct strbuf buf
= STRBUF_INIT
;
683 const int hexsz
= the_hash_algo
->hexsz
;
684 int seen_end_of_options
= 0;
685 enum format_type format
= FORMAT_DEFAULT
;
687 if (argc
> 1 && !strcmp("--parseopt", argv
[1]))
688 return cmd_parseopt(argc
- 1, argv
+ 1, prefix
);
690 if (argc
> 1 && !strcmp("--sq-quote", argv
[1]))
691 return cmd_sq_quote(argc
- 2, argv
+ 2);
693 if (argc
> 1 && !strcmp("-h", argv
[1]))
694 usage(builtin_rev_parse_usage
);
696 for (i
= 1; i
< argc
; i
++) {
697 if (!strcmp(argv
[i
], "--")) {
703 /* No options; just report on whether we're in a git repo or not. */
705 setup_git_directory();
706 git_config(git_default_config
, NULL
);
710 for (i
= 1; i
< argc
; i
++) {
711 const char *arg
= argv
[i
];
714 if (show_file(arg
, output_prefix
) && as_is
< 2)
715 verify_filename(prefix
, arg
, 0);
719 if (!seen_end_of_options
) {
720 if (!strcmp(arg
, "--local-env-vars")) {
722 for (i
= 0; local_repo_env
[i
]; i
++)
723 printf("%s\n", local_repo_env
[i
]);
726 if (!strcmp(arg
, "--resolve-git-dir")) {
727 const char *gitdir
= argv
[++i
];
729 die(_("--resolve-git-dir requires an argument"));
730 gitdir
= resolve_gitdir(gitdir
);
732 die(_("not a gitdir '%s'"), argv
[i
]);
738 /* The rest of the options require a git repository. */
739 if (!did_repo_setup
) {
740 prefix
= setup_git_directory();
741 git_config(git_default_config
, NULL
);
744 prepare_repo_settings(the_repository
);
745 the_repository
->settings
.command_requires_full_index
= 0;
748 if (!strcmp(arg
, "--")) {
750 /* Pass on the "--" if we show anything but files.. */
751 if (filter
& (DO_FLAGS
| DO_REVS
))
756 if (!seen_end_of_options
&& *arg
== '-') {
757 if (!strcmp(arg
, "--git-path")) {
759 die(_("--git-path requires an argument"));
761 print_path(git_path("%s", argv
[i
+ 1]), prefix
,
763 DEFAULT_RELATIVE_IF_SHARED
);
767 if (!strcmp(arg
,"-n")) {
769 die(_("-n requires an argument"));
770 if ((filter
& DO_FLAGS
) && (filter
& DO_REVS
)) {
776 if (starts_with(arg
, "-n")) {
777 if ((filter
& DO_FLAGS
) && (filter
& DO_REVS
))
781 if (opt_with_value(arg
, "--path-format", &arg
)) {
783 die(_("--path-format requires an argument"));
784 if (!strcmp(arg
, "absolute")) {
785 format
= FORMAT_CANONICAL
;
786 } else if (!strcmp(arg
, "relative")) {
787 format
= FORMAT_RELATIVE
;
789 die(_("unknown argument to --path-format: %s"), arg
);
793 if (!strcmp(arg
, "--default")) {
796 die(_("--default requires an argument"));
799 if (!strcmp(arg
, "--prefix")) {
802 die(_("--prefix requires an argument"));
803 startup_info
->prefix
= prefix
;
807 if (!strcmp(arg
, "--revs-only")) {
811 if (!strcmp(arg
, "--no-revs")) {
815 if (!strcmp(arg
, "--flags")) {
816 filter
&= ~DO_NONFLAGS
;
819 if (!strcmp(arg
, "--no-flags")) {
823 if (!strcmp(arg
, "--verify")) {
824 filter
&= ~(DO_FLAGS
|DO_NOREV
);
828 if (!strcmp(arg
, "--quiet") || !strcmp(arg
, "-q")) {
830 flags
|= GET_OID_QUIETLY
;
833 if (opt_with_value(arg
, "--short", &arg
)) {
834 filter
&= ~(DO_FLAGS
|DO_NOREV
);
836 abbrev
= DEFAULT_ABBREV
;
839 abbrev
= strtoul(arg
, NULL
, 10);
840 if (abbrev
< MINIMUM_ABBREV
)
841 abbrev
= MINIMUM_ABBREV
;
842 else if (hexsz
<= abbrev
)
846 if (!strcmp(arg
, "--sq")) {
850 if (!strcmp(arg
, "--not")) {
851 show_type
^= REVERSED
;
854 if (!strcmp(arg
, "--symbolic")) {
855 symbolic
= SHOW_SYMBOLIC_ASIS
;
858 if (!strcmp(arg
, "--symbolic-full-name")) {
859 symbolic
= SHOW_SYMBOLIC_FULL
;
862 if (opt_with_value(arg
, "--abbrev-ref", &arg
)) {
864 abbrev_ref_strict
= warn_ambiguous_refs
;
866 if (!strcmp(arg
, "strict"))
867 abbrev_ref_strict
= 1;
868 else if (!strcmp(arg
, "loose"))
869 abbrev_ref_strict
= 0;
871 die(_("unknown mode for --abbrev-ref: %s"),
876 if (!strcmp(arg
, "--all")) {
877 for_each_ref(show_reference
, NULL
);
878 clear_ref_exclusions(&ref_excludes
);
881 if (skip_prefix(arg
, "--disambiguate=", &arg
)) {
882 repo_for_each_abbrev(the_repository
, arg
,
886 if (!strcmp(arg
, "--bisect")) {
887 for_each_fullref_in("refs/bisect/bad", show_reference
, NULL
);
888 for_each_fullref_in("refs/bisect/good", anti_reference
, NULL
);
891 if (opt_with_value(arg
, "--branches", &arg
)) {
892 if (ref_excludes
.hidden_refs_configured
)
893 return error(_("--exclude-hidden cannot be used together with --branches"));
894 handle_ref_opt(arg
, "refs/heads/");
897 if (opt_with_value(arg
, "--tags", &arg
)) {
898 if (ref_excludes
.hidden_refs_configured
)
899 return error(_("--exclude-hidden cannot be used together with --tags"));
900 handle_ref_opt(arg
, "refs/tags/");
903 if (skip_prefix(arg
, "--glob=", &arg
)) {
904 handle_ref_opt(arg
, NULL
);
907 if (opt_with_value(arg
, "--remotes", &arg
)) {
908 if (ref_excludes
.hidden_refs_configured
)
909 return error(_("--exclude-hidden cannot be used together with --remotes"));
910 handle_ref_opt(arg
, "refs/remotes/");
913 if (skip_prefix(arg
, "--exclude=", &arg
)) {
914 add_ref_exclusion(&ref_excludes
, arg
);
917 if (skip_prefix(arg
, "--exclude-hidden=", &arg
)) {
918 exclude_hidden_refs(&ref_excludes
, arg
);
921 if (!strcmp(arg
, "--show-toplevel")) {
922 const char *work_tree
= get_git_work_tree();
924 print_path(work_tree
, prefix
, format
, DEFAULT_UNMODIFIED
);
926 die(_("this operation must be run in a work tree"));
929 if (!strcmp(arg
, "--show-superproject-working-tree")) {
930 struct strbuf superproject
= STRBUF_INIT
;
931 if (get_superproject_working_tree(&superproject
))
932 print_path(superproject
.buf
, prefix
, format
, DEFAULT_UNMODIFIED
);
933 strbuf_release(&superproject
);
936 if (!strcmp(arg
, "--show-prefix")) {
943 if (!strcmp(arg
, "--show-cdup")) {
944 const char *pfx
= prefix
;
945 if (!is_inside_work_tree()) {
946 const char *work_tree
=
949 printf("%s\n", work_tree
);
953 pfx
= strchr(pfx
, '/');
962 if (!strcmp(arg
, "--git-dir") ||
963 !strcmp(arg
, "--absolute-git-dir")) {
964 const char *gitdir
= getenv(GIT_DIR_ENVIRONMENT
);
967 enum format_type wanted
= format
;
968 if (arg
[2] == 'g') { /* --git-dir */
970 print_path(gitdir
, prefix
, format
, DEFAULT_UNMODIFIED
);
974 print_path(".git", prefix
, format
, DEFAULT_UNMODIFIED
);
977 } else { /* --absolute-git-dir */
978 wanted
= FORMAT_CANONICAL
;
979 if (!gitdir
&& !prefix
)
982 struct strbuf realpath
= STRBUF_INIT
;
983 strbuf_realpath(&realpath
, gitdir
, 1);
985 strbuf_release(&realpath
);
992 strbuf_addf(&buf
, "%s%s.git", cwd
, len
&& cwd
[len
-1] != '/' ? "/" : "");
994 print_path(buf
.buf
, prefix
, wanted
, DEFAULT_CANONICAL
);
997 if (!strcmp(arg
, "--git-common-dir")) {
998 print_path(get_git_common_dir(), prefix
, format
, DEFAULT_RELATIVE_IF_SHARED
);
1001 if (!strcmp(arg
, "--is-inside-git-dir")) {
1002 printf("%s\n", is_inside_git_dir() ? "true"
1006 if (!strcmp(arg
, "--is-inside-work-tree")) {
1007 printf("%s\n", is_inside_work_tree() ? "true"
1011 if (!strcmp(arg
, "--is-bare-repository")) {
1012 printf("%s\n", is_bare_repository() ? "true"
1016 if (!strcmp(arg
, "--is-shallow-repository")) {
1018 is_repository_shallow(the_repository
) ? "true"
1022 if (!strcmp(arg
, "--shared-index-path")) {
1023 if (repo_read_index(the_repository
) < 0)
1024 die(_("Could not read the index"));
1025 if (the_index
.split_index
) {
1026 const struct object_id
*oid
= &the_index
.split_index
->base_oid
;
1027 const char *path
= git_path("sharedindex.%s", oid_to_hex(oid
));
1028 print_path(path
, prefix
, format
, DEFAULT_RELATIVE
);
1032 if (skip_prefix(arg
, "--since=", &arg
)) {
1033 show_datestring("--max-age=", arg
);
1036 if (skip_prefix(arg
, "--after=", &arg
)) {
1037 show_datestring("--max-age=", arg
);
1040 if (skip_prefix(arg
, "--before=", &arg
)) {
1041 show_datestring("--min-age=", arg
);
1044 if (skip_prefix(arg
, "--until=", &arg
)) {
1045 show_datestring("--min-age=", arg
);
1048 if (opt_with_value(arg
, "--show-object-format", &arg
)) {
1049 const char *val
= arg
? arg
: "storage";
1051 if (strcmp(val
, "storage") &&
1052 strcmp(val
, "input") &&
1053 strcmp(val
, "output"))
1054 die(_("unknown mode for --show-object-format: %s"),
1056 puts(the_hash_algo
->name
);
1059 if (!strcmp(arg
, "--end-of-options")) {
1060 seen_end_of_options
= 1;
1061 if (filter
& (DO_FLAGS
| DO_REVS
))
1065 if (show_flag(arg
) && verify
)
1066 die_no_single_rev(quiet
);
1070 /* Not a flag argument */
1071 if (try_difference(arg
))
1073 if (try_parent_shorthands(arg
))
1081 if (!get_oid_with_context(the_repository
, name
,
1082 flags
, &oid
, &unused
)) {
1086 show_rev(type
, &oid
, name
);
1090 die_no_single_rev(quiet
);
1092 die(_("bad revision '%s'"), arg
);
1094 if (!show_file(arg
, output_prefix
))
1096 verify_filename(prefix
, arg
, 1);
1098 strbuf_release(&buf
);
1100 if (revs_count
== 1) {
1101 show_rev(type
, &oid
, name
);
1103 } else if (revs_count
== 0 && show_default())
1105 die_no_single_rev(quiet
);