4 * Copyright (C) Linus Torvalds, 2005
6 #define USE_THE_INDEX_VARIABLE
12 #include "environment.h"
17 #include "object-name.h"
18 #include "parse-options.h"
20 #include "read-cache-ll.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.
160 full
= shorten_unambiguous_ref(full
,
162 show_with_type(type
, full
);
164 default: /* ambiguous */
165 error("refname '%s' is ambiguous", name
);
170 show_with_type(type
, name
);
175 repo_find_unique_abbrev(the_repository
, oid
, abbrev
));
177 show_with_type(type
, oid_to_hex(oid
));
180 /* Output a flag, only if filter allows it. */
181 static int show_flag(const char *arg
)
183 if (!(filter
& DO_FLAGS
))
185 if (filter
& (is_rev_argument(arg
) ? DO_REVS
: DO_NOREV
)) {
192 static int show_default(void)
197 struct object_id oid
;
200 if (!repo_get_oid(the_repository
, s
, &oid
)) {
201 show_rev(NORMAL
, &oid
, s
);
208 static int show_reference(const char *refname
, const struct object_id
*oid
,
209 int flag UNUSED
, void *cb_data UNUSED
)
211 if (ref_excluded(&ref_excludes
, refname
))
213 show_rev(NORMAL
, oid
, refname
);
217 static int anti_reference(const char *refname
, const struct object_id
*oid
,
218 int flag UNUSED
, void *cb_data UNUSED
)
220 show_rev(REVERSED
, oid
, refname
);
224 static int show_abbrev(const struct object_id
*oid
, void *cb_data
)
226 show_rev(NORMAL
, oid
, NULL
);
230 static void show_datestring(const char *flag
, const char *datestr
)
234 /* date handling requires both flags and revs */
235 if ((filter
& (DO_FLAGS
| DO_REVS
)) != (DO_FLAGS
| DO_REVS
))
237 buffer
= xstrfmt("%s%"PRItime
, flag
, approxidate(datestr
));
242 static int show_file(const char *arg
, int output_prefix
)
245 if ((filter
& (DO_NONFLAGS
|DO_NOREV
)) == (DO_NONFLAGS
|DO_NOREV
)) {
247 const char *prefix
= startup_info
->prefix
;
248 char *fname
= prefix_filename(prefix
, arg
);
258 static int try_difference(const char *arg
)
261 struct object_id start_oid
;
262 struct object_id end_oid
;
266 static const char head_by_default
[] = "HEAD";
268 if (!(dotdot
= strstr(arg
, "..")))
272 symmetric
= (*end
== '.');
278 end
= head_by_default
;
280 start
= head_by_default
;
282 if (start
== head_by_default
&& end
== head_by_default
&&
285 * Just ".."? That is not a range but the
286 * pathspec for the parent directory.
292 if (!repo_get_oid_committish(the_repository
, start
, &start_oid
) && !repo_get_oid_committish(the_repository
, end
, &end_oid
)) {
293 show_rev(NORMAL
, &end_oid
, end
);
294 show_rev(symmetric
? NORMAL
: REVERSED
, &start_oid
, start
);
296 struct commit_list
*exclude
;
297 struct commit
*a
, *b
;
298 a
= lookup_commit_reference(the_repository
, &start_oid
);
299 b
= lookup_commit_reference(the_repository
, &end_oid
);
304 exclude
= repo_get_merge_bases(the_repository
, a
, b
);
306 struct commit
*commit
= pop_commit(&exclude
);
307 show_rev(REVERSED
, &commit
->object
.oid
, NULL
);
317 static int try_parent_shorthands(const char *arg
)
320 struct object_id oid
;
321 struct commit
*commit
;
322 struct commit_list
*parents
;
325 int include_parents
= 0;
326 int exclude_parent
= 0;
328 if ((dotdot
= strstr(arg
, "^!"))) {
332 } else if ((dotdot
= strstr(arg
, "^@"))) {
336 } else if ((dotdot
= strstr(arg
, "^-"))) {
342 exclude_parent
= strtoul(dotdot
+ 2, &end
, 10);
343 if (*end
!= '\0' || !exclude_parent
)
350 if (repo_get_oid_committish(the_repository
, arg
, &oid
) ||
351 !(commit
= lookup_commit_reference(the_repository
, &oid
))) {
356 if (exclude_parent
&&
357 exclude_parent
> commit_list_count(commit
->parents
)) {
363 show_rev(NORMAL
, &oid
, arg
);
364 for (parents
= commit
->parents
, parent_number
= 1;
366 parents
= parents
->next
, parent_number
++) {
369 if (exclude_parent
&& parent_number
!= exclude_parent
)
373 name
= xstrfmt("%s^%d", arg
, parent_number
);
374 show_rev(include_parents
? NORMAL
: REVERSED
,
375 &parents
->item
->object
.oid
, name
);
383 static int parseopt_dump(const struct option
*o
, const char *arg
, int unset
)
385 struct strbuf
*parsed
= o
->value
;
387 strbuf_addf(parsed
, " --no-%s", o
->long_name
);
388 else if (o
->short_name
&& (o
->long_name
== NULL
|| !stuck_long
))
389 strbuf_addf(parsed
, " -%c", o
->short_name
);
391 strbuf_addf(parsed
, " --%s", o
->long_name
);
394 strbuf_addch(parsed
, ' ');
395 else if (o
->long_name
)
396 strbuf_addch(parsed
, '=');
397 sq_quote_buf(parsed
, arg
);
402 static const char *skipspaces(const char *s
)
409 static char *findspace(const char *s
)
417 static int cmd_parseopt(int argc
, const char **argv
, const char *prefix
)
419 static int keep_dashdash
= 0, stop_at_non_option
= 0;
420 static char const * const parseopt_usage
[] = {
421 N_("git rev-parse --parseopt [<options>] -- [<args>...]"),
424 static struct option parseopt_opts
[] = {
425 OPT_BOOL(0, "keep-dashdash", &keep_dashdash
,
426 N_("keep the `--` passed as an arg")),
427 OPT_BOOL(0, "stop-at-non-option", &stop_at_non_option
,
428 N_("stop parsing after the "
429 "first non-option argument")),
430 OPT_BOOL(0, "stuck-long", &stuck_long
,
431 N_("output in stuck long form")),
434 static const char * const flag_chars
= "*=?!";
436 struct strbuf sb
= STRBUF_INIT
, parsed
= STRBUF_INIT
;
437 const char **usage
= NULL
;
438 struct option
*opts
= NULL
;
439 int onb
= 0, osz
= 0, unb
= 0, usz
= 0;
441 strbuf_addstr(&parsed
, "set --");
442 argc
= parse_options(argc
, argv
, prefix
, parseopt_opts
, parseopt_usage
,
443 PARSE_OPT_KEEP_DASHDASH
);
444 if (argc
< 1 || strcmp(argv
[0], "--"))
445 usage_with_options(parseopt_usage
, parseopt_opts
);
447 /* get the usage up to the first line with a -- on it */
449 if (strbuf_getline(&sb
, stdin
) == EOF
)
450 die(_("premature end of input"));
451 ALLOC_GROW(usage
, unb
+ 1, usz
);
452 if (!strcmp("--", sb
.buf
)) {
454 die(_("no usage string given before the `--' separator"));
458 usage
[unb
++] = strbuf_detach(&sb
, NULL
);
461 /* parse: (<short>|<short>,<long>|<long>)[*=?!]*<arghint>? SP+ <help> */
462 while (strbuf_getline(&sb
, stdin
) != EOF
) {
470 ALLOC_GROW(opts
, onb
+ 1, osz
);
471 memset(opts
+ onb
, 0, sizeof(opts
[onb
]));
474 help
= findspace(sb
.buf
);
475 if (!help
|| sb
.buf
== help
) {
476 o
->type
= OPTION_GROUP
;
477 o
->help
= xstrdup(skipspaces(sb
.buf
));
483 o
->type
= OPTION_CALLBACK
;
484 o
->help
= xstrdup(skipspaces(help
+1));
486 o
->flags
= PARSE_OPT_NOARG
;
487 o
->callback
= &parseopt_dump
;
490 s
= strpbrk(sb
.buf
, flag_chars
);
495 die(_("missing opt-spec before option flags"));
497 if (s
- sb
.buf
== 1) /* short option only */
498 o
->short_name
= *sb
.buf
;
499 else if (sb
.buf
[1] != ',') /* long option only */
500 o
->long_name
= xmemdupz(sb
.buf
, s
- sb
.buf
);
502 o
->short_name
= *sb
.buf
;
503 o
->long_name
= xmemdupz(sb
.buf
+ 2, s
- sb
.buf
- 2);
510 o
->flags
&= ~PARSE_OPT_NOARG
;
513 o
->flags
&= ~PARSE_OPT_NOARG
;
514 o
->flags
|= PARSE_OPT_OPTARG
;
517 o
->flags
|= PARSE_OPT_NONEG
;
520 o
->flags
|= PARSE_OPT_HIDDEN
;
528 o
->argh
= xmemdupz(s
, help
- s
);
532 /* put an OPT_END() */
533 ALLOC_GROW(opts
, onb
+ 1, osz
);
534 memset(opts
+ onb
, 0, sizeof(opts
[onb
]));
535 argc
= parse_options(argc
, argv
, prefix
, opts
, usage
,
536 (keep_dashdash
? PARSE_OPT_KEEP_DASHDASH
: 0) |
537 (stop_at_non_option
? PARSE_OPT_STOP_AT_NON_OPTION
: 0) |
538 PARSE_OPT_SHELL_EVAL
);
540 strbuf_addstr(&parsed
, " --");
541 sq_quote_argv(&parsed
, argv
);
543 strbuf_release(&parsed
);
547 static int cmd_sq_quote(int argc
, const char **argv
)
549 struct strbuf buf
= STRBUF_INIT
;
552 sq_quote_argv(&buf
, argv
);
553 printf("%s\n", buf
.buf
);
554 strbuf_release(&buf
);
559 static void die_no_single_rev(int quiet
)
564 die(_("Needed a single revision"));
567 static const char builtin_rev_parse_usage
[] =
568 N_("git rev-parse --parseopt [<options>] -- [<args>...]\n"
569 " or: git rev-parse --sq-quote [<arg>...]\n"
570 " or: git rev-parse [<options>] [<arg>...]\n"
572 "Run \"git rev-parse --parseopt -h\" for more information on the first usage.");
575 * Parse "opt" or "opt=<value>", setting value respectively to either
576 * NULL or the string after "=".
578 static int opt_with_value(const char *arg
, const char *opt
, const char **value
)
580 if (skip_prefix(arg
, opt
, &arg
)) {
593 static void handle_ref_opt(const char *pattern
, const char *prefix
)
596 for_each_glob_ref_in(show_reference
, pattern
, prefix
, NULL
);
598 for_each_ref_in(prefix
, show_reference
, NULL
);
599 clear_ref_exclusions(&ref_excludes
);
603 /* We would like a relative path. */
605 /* We would like a canonical absolute path. */
607 /* We would like the default behavior. */
612 /* Our default is a relative path. */
614 /* Our default is a relative path if there's a shared root. */
615 DEFAULT_RELATIVE_IF_SHARED
,
616 /* Our default is a canonical absolute path. */
618 /* Our default is not to modify the item. */
622 static void print_path(const char *path
, const char *prefix
, enum format_type format
, enum default_type def
)
626 * We don't ever produce a relative path if prefix is NULL, so set the
627 * prefix to the current directory so that we can produce a relative
628 * path whenever possible. If we're using RELATIVE_IF_SHARED mode, then
629 * we want an absolute path unless the two share a common prefix, so don't
630 * set it in that case, since doing so causes a relative path to always
631 * be produced if possible.
633 if (!prefix
&& (format
!= FORMAT_DEFAULT
|| def
!= DEFAULT_RELATIVE_IF_SHARED
))
634 prefix
= cwd
= xgetcwd();
635 if (format
== FORMAT_DEFAULT
&& def
== DEFAULT_UNMODIFIED
) {
637 } else if (format
== FORMAT_RELATIVE
||
638 (format
== FORMAT_DEFAULT
&& def
== DEFAULT_RELATIVE
)) {
640 * In order for relative_path to work as expected, we need to
641 * make sure that both paths are absolute paths. If we don't,
642 * we can end up with an unexpected absolute path that the user
645 struct strbuf buf
= STRBUF_INIT
, realbuf
= STRBUF_INIT
, prefixbuf
= STRBUF_INIT
;
646 if (!is_absolute_path(path
)) {
647 strbuf_realpath_forgiving(&realbuf
, path
, 1);
650 if (!is_absolute_path(prefix
)) {
651 strbuf_realpath_forgiving(&prefixbuf
, prefix
, 1);
652 prefix
= prefixbuf
.buf
;
654 puts(relative_path(path
, prefix
, &buf
));
655 strbuf_release(&buf
);
656 strbuf_release(&realbuf
);
657 strbuf_release(&prefixbuf
);
658 } else if (format
== FORMAT_DEFAULT
&& def
== DEFAULT_RELATIVE_IF_SHARED
) {
659 struct strbuf buf
= STRBUF_INIT
;
660 puts(relative_path(path
, prefix
, &buf
));
661 strbuf_release(&buf
);
663 struct strbuf buf
= STRBUF_INIT
;
664 strbuf_realpath_forgiving(&buf
, path
, 1);
666 strbuf_release(&buf
);
671 int cmd_rev_parse(int argc
, const char **argv
, const char *prefix
)
673 int i
, as_is
= 0, verify
= 0, quiet
= 0, revs_count
= 0, type
= 0;
674 int did_repo_setup
= 0;
675 int has_dashdash
= 0;
676 int output_prefix
= 0;
677 struct object_id oid
;
678 unsigned int flags
= 0;
679 const char *name
= NULL
;
680 struct object_context unused
;
681 struct strbuf buf
= STRBUF_INIT
;
682 const int hexsz
= the_hash_algo
->hexsz
;
683 int seen_end_of_options
= 0;
684 enum format_type format
= FORMAT_DEFAULT
;
686 if (argc
> 1 && !strcmp("--parseopt", argv
[1]))
687 return cmd_parseopt(argc
- 1, argv
+ 1, prefix
);
689 if (argc
> 1 && !strcmp("--sq-quote", argv
[1]))
690 return cmd_sq_quote(argc
- 2, argv
+ 2);
692 if (argc
> 1 && !strcmp("-h", argv
[1]))
693 usage(builtin_rev_parse_usage
);
695 for (i
= 1; i
< argc
; i
++) {
696 if (!strcmp(argv
[i
], "--")) {
702 /* No options; just report on whether we're in a git repo or not. */
704 setup_git_directory();
705 git_config(git_default_config
, NULL
);
709 for (i
= 1; i
< argc
; i
++) {
710 const char *arg
= argv
[i
];
713 if (show_file(arg
, output_prefix
) && as_is
< 2)
714 verify_filename(prefix
, arg
, 0);
718 if (!seen_end_of_options
) {
719 if (!strcmp(arg
, "--local-env-vars")) {
721 for (i
= 0; local_repo_env
[i
]; i
++)
722 printf("%s\n", local_repo_env
[i
]);
725 if (!strcmp(arg
, "--resolve-git-dir")) {
726 const char *gitdir
= argv
[++i
];
728 die(_("--resolve-git-dir requires an argument"));
729 gitdir
= resolve_gitdir(gitdir
);
731 die(_("not a gitdir '%s'"), argv
[i
]);
737 /* The rest of the options require a git repository. */
738 if (!did_repo_setup
) {
739 prefix
= setup_git_directory();
740 git_config(git_default_config
, NULL
);
743 prepare_repo_settings(the_repository
);
744 the_repository
->settings
.command_requires_full_index
= 0;
747 if (!strcmp(arg
, "--")) {
749 /* Pass on the "--" if we show anything but files.. */
750 if (filter
& (DO_FLAGS
| DO_REVS
))
755 if (!seen_end_of_options
&& *arg
== '-') {
756 if (!strcmp(arg
, "--git-path")) {
758 die(_("--git-path requires an argument"));
760 print_path(git_path("%s", argv
[i
+ 1]), prefix
,
762 DEFAULT_RELATIVE_IF_SHARED
);
766 if (!strcmp(arg
,"-n")) {
768 die(_("-n requires an argument"));
769 if ((filter
& DO_FLAGS
) && (filter
& DO_REVS
)) {
775 if (starts_with(arg
, "-n")) {
776 if ((filter
& DO_FLAGS
) && (filter
& DO_REVS
))
780 if (opt_with_value(arg
, "--path-format", &arg
)) {
782 die(_("--path-format requires an argument"));
783 if (!strcmp(arg
, "absolute")) {
784 format
= FORMAT_CANONICAL
;
785 } else if (!strcmp(arg
, "relative")) {
786 format
= FORMAT_RELATIVE
;
788 die(_("unknown argument to --path-format: %s"), arg
);
792 if (!strcmp(arg
, "--default")) {
795 die(_("--default requires an argument"));
798 if (!strcmp(arg
, "--prefix")) {
801 die(_("--prefix requires an argument"));
802 startup_info
->prefix
= prefix
;
806 if (!strcmp(arg
, "--revs-only")) {
810 if (!strcmp(arg
, "--no-revs")) {
814 if (!strcmp(arg
, "--flags")) {
815 filter
&= ~DO_NONFLAGS
;
818 if (!strcmp(arg
, "--no-flags")) {
822 if (!strcmp(arg
, "--verify")) {
823 filter
&= ~(DO_FLAGS
|DO_NOREV
);
827 if (!strcmp(arg
, "--quiet") || !strcmp(arg
, "-q")) {
829 flags
|= GET_OID_QUIETLY
;
832 if (opt_with_value(arg
, "--short", &arg
)) {
833 filter
&= ~(DO_FLAGS
|DO_NOREV
);
835 abbrev
= DEFAULT_ABBREV
;
838 abbrev
= strtoul(arg
, NULL
, 10);
839 if (abbrev
< MINIMUM_ABBREV
)
840 abbrev
= MINIMUM_ABBREV
;
841 else if (hexsz
<= abbrev
)
845 if (!strcmp(arg
, "--sq")) {
849 if (!strcmp(arg
, "--not")) {
850 show_type
^= REVERSED
;
853 if (!strcmp(arg
, "--symbolic")) {
854 symbolic
= SHOW_SYMBOLIC_ASIS
;
857 if (!strcmp(arg
, "--symbolic-full-name")) {
858 symbolic
= SHOW_SYMBOLIC_FULL
;
861 if (opt_with_value(arg
, "--abbrev-ref", &arg
)) {
863 abbrev_ref_strict
= warn_ambiguous_refs
;
865 if (!strcmp(arg
, "strict"))
866 abbrev_ref_strict
= 1;
867 else if (!strcmp(arg
, "loose"))
868 abbrev_ref_strict
= 0;
870 die(_("unknown mode for --abbrev-ref: %s"),
875 if (!strcmp(arg
, "--all")) {
876 for_each_ref(show_reference
, NULL
);
877 clear_ref_exclusions(&ref_excludes
);
880 if (skip_prefix(arg
, "--disambiguate=", &arg
)) {
881 repo_for_each_abbrev(the_repository
, arg
,
885 if (!strcmp(arg
, "--bisect")) {
886 for_each_fullref_in("refs/bisect/bad", show_reference
, NULL
);
887 for_each_fullref_in("refs/bisect/good", anti_reference
, NULL
);
890 if (opt_with_value(arg
, "--branches", &arg
)) {
891 if (ref_excludes
.hidden_refs_configured
)
892 return error(_("--exclude-hidden cannot be used together with --branches"));
893 handle_ref_opt(arg
, "refs/heads/");
896 if (opt_with_value(arg
, "--tags", &arg
)) {
897 if (ref_excludes
.hidden_refs_configured
)
898 return error(_("--exclude-hidden cannot be used together with --tags"));
899 handle_ref_opt(arg
, "refs/tags/");
902 if (skip_prefix(arg
, "--glob=", &arg
)) {
903 handle_ref_opt(arg
, NULL
);
906 if (opt_with_value(arg
, "--remotes", &arg
)) {
907 if (ref_excludes
.hidden_refs_configured
)
908 return error(_("--exclude-hidden cannot be used together with --remotes"));
909 handle_ref_opt(arg
, "refs/remotes/");
912 if (skip_prefix(arg
, "--exclude=", &arg
)) {
913 add_ref_exclusion(&ref_excludes
, arg
);
916 if (skip_prefix(arg
, "--exclude-hidden=", &arg
)) {
917 exclude_hidden_refs(&ref_excludes
, arg
);
920 if (!strcmp(arg
, "--show-toplevel")) {
921 const char *work_tree
= get_git_work_tree();
923 print_path(work_tree
, prefix
, format
, DEFAULT_UNMODIFIED
);
925 die(_("this operation must be run in a work tree"));
928 if (!strcmp(arg
, "--show-superproject-working-tree")) {
929 struct strbuf superproject
= STRBUF_INIT
;
930 if (get_superproject_working_tree(&superproject
))
931 print_path(superproject
.buf
, prefix
, format
, DEFAULT_UNMODIFIED
);
932 strbuf_release(&superproject
);
935 if (!strcmp(arg
, "--show-prefix")) {
942 if (!strcmp(arg
, "--show-cdup")) {
943 const char *pfx
= prefix
;
944 if (!is_inside_work_tree()) {
945 const char *work_tree
=
948 printf("%s\n", work_tree
);
952 pfx
= strchr(pfx
, '/');
961 if (!strcmp(arg
, "--git-dir") ||
962 !strcmp(arg
, "--absolute-git-dir")) {
963 const char *gitdir
= getenv(GIT_DIR_ENVIRONMENT
);
966 enum format_type wanted
= format
;
967 if (arg
[2] == 'g') { /* --git-dir */
969 print_path(gitdir
, prefix
, format
, DEFAULT_UNMODIFIED
);
973 print_path(".git", prefix
, format
, DEFAULT_UNMODIFIED
);
976 } else { /* --absolute-git-dir */
977 wanted
= FORMAT_CANONICAL
;
978 if (!gitdir
&& !prefix
)
981 struct strbuf realpath
= STRBUF_INIT
;
982 strbuf_realpath(&realpath
, gitdir
, 1);
984 strbuf_release(&realpath
);
991 strbuf_addf(&buf
, "%s%s.git", cwd
, len
&& cwd
[len
-1] != '/' ? "/" : "");
993 print_path(buf
.buf
, prefix
, wanted
, DEFAULT_CANONICAL
);
996 if (!strcmp(arg
, "--git-common-dir")) {
997 print_path(get_git_common_dir(), prefix
, format
, DEFAULT_RELATIVE_IF_SHARED
);
1000 if (!strcmp(arg
, "--is-inside-git-dir")) {
1001 printf("%s\n", is_inside_git_dir() ? "true"
1005 if (!strcmp(arg
, "--is-inside-work-tree")) {
1006 printf("%s\n", is_inside_work_tree() ? "true"
1010 if (!strcmp(arg
, "--is-bare-repository")) {
1011 printf("%s\n", is_bare_repository() ? "true"
1015 if (!strcmp(arg
, "--is-shallow-repository")) {
1017 is_repository_shallow(the_repository
) ? "true"
1021 if (!strcmp(arg
, "--shared-index-path")) {
1022 if (repo_read_index(the_repository
) < 0)
1023 die(_("Could not read the index"));
1024 if (the_index
.split_index
) {
1025 const struct object_id
*oid
= &the_index
.split_index
->base_oid
;
1026 const char *path
= git_path("sharedindex.%s", oid_to_hex(oid
));
1027 print_path(path
, prefix
, format
, DEFAULT_RELATIVE
);
1031 if (skip_prefix(arg
, "--since=", &arg
)) {
1032 show_datestring("--max-age=", arg
);
1035 if (skip_prefix(arg
, "--after=", &arg
)) {
1036 show_datestring("--max-age=", arg
);
1039 if (skip_prefix(arg
, "--before=", &arg
)) {
1040 show_datestring("--min-age=", arg
);
1043 if (skip_prefix(arg
, "--until=", &arg
)) {
1044 show_datestring("--min-age=", arg
);
1047 if (opt_with_value(arg
, "--show-object-format", &arg
)) {
1048 const char *val
= arg
? arg
: "storage";
1050 if (strcmp(val
, "storage") &&
1051 strcmp(val
, "input") &&
1052 strcmp(val
, "output"))
1053 die(_("unknown mode for --show-object-format: %s"),
1055 puts(the_hash_algo
->name
);
1058 if (!strcmp(arg
, "--end-of-options")) {
1059 seen_end_of_options
= 1;
1060 if (filter
& (DO_FLAGS
| DO_REVS
))
1064 if (show_flag(arg
) && verify
)
1065 die_no_single_rev(quiet
);
1069 /* Not a flag argument */
1070 if (try_difference(arg
))
1072 if (try_parent_shorthands(arg
))
1080 if (!get_oid_with_context(the_repository
, name
,
1081 flags
, &oid
, &unused
)) {
1085 show_rev(type
, &oid
, name
);
1089 die_no_single_rev(quiet
);
1091 die(_("bad revision '%s'"), arg
);
1093 if (!show_file(arg
, output_prefix
))
1095 verify_filename(prefix
, arg
, 1);
1097 strbuf_release(&buf
);
1099 if (revs_count
== 1) {
1100 show_rev(type
, &oid
, name
);
1102 } else if (revs_count
== 0 && show_default())
1104 die_no_single_rev(quiet
);