4 * Copyright (C) Linus Torvalds, 2005
6 #define USE_THE_INDEX_VARIABLE
11 #include "environment.h"
17 #include "object-name.h"
18 #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.
162 full
= shorten_unambiguous_ref(full
,
166 show_with_type(type
, full
);
168 default: /* ambiguous */
169 error("refname '%s' is ambiguous", name
);
174 show_with_type(type
, name
);
179 repo_find_unique_abbrev(the_repository
, oid
, abbrev
));
181 show_with_type(type
, oid_to_hex(oid
));
184 /* Output a flag, only if filter allows it. */
185 static int show_flag(const char *arg
)
187 if (!(filter
& DO_FLAGS
))
189 if (filter
& (is_rev_argument(arg
) ? DO_REVS
: DO_NOREV
)) {
196 static int show_default(void)
201 struct object_id oid
;
204 if (!repo_get_oid(the_repository
, s
, &oid
)) {
205 show_rev(NORMAL
, &oid
, s
);
212 static int show_reference(const char *refname
, const struct object_id
*oid
,
213 int flag UNUSED
, void *cb_data UNUSED
)
215 if (ref_excluded(&ref_excludes
, refname
))
217 show_rev(NORMAL
, oid
, refname
);
221 static int anti_reference(const char *refname
, const struct object_id
*oid
,
222 int flag UNUSED
, void *cb_data UNUSED
)
224 show_rev(REVERSED
, oid
, refname
);
228 static int show_abbrev(const struct object_id
*oid
, void *cb_data UNUSED
)
230 show_rev(NORMAL
, oid
, NULL
);
234 static void show_datestring(const char *flag
, const char *datestr
)
238 /* date handling requires both flags and revs */
239 if ((filter
& (DO_FLAGS
| DO_REVS
)) != (DO_FLAGS
| DO_REVS
))
241 buffer
= xstrfmt("%s%"PRItime
, flag
, approxidate(datestr
));
246 static int show_file(const char *arg
, int output_prefix
)
249 if ((filter
& (DO_NONFLAGS
|DO_NOREV
)) == (DO_NONFLAGS
|DO_NOREV
)) {
251 const char *prefix
= startup_info
->prefix
;
252 char *fname
= prefix_filename(prefix
, arg
);
262 static int try_difference(const char *arg
)
265 struct object_id start_oid
;
266 struct object_id end_oid
;
270 static const char head_by_default
[] = "HEAD";
272 if (!(dotdot
= strstr(arg
, "..")))
276 symmetric
= (*end
== '.');
282 end
= head_by_default
;
284 start
= head_by_default
;
286 if (start
== head_by_default
&& end
== head_by_default
&&
289 * Just ".."? That is not a range but the
290 * pathspec for the parent directory.
296 if (!repo_get_oid_committish(the_repository
, start
, &start_oid
) && !repo_get_oid_committish(the_repository
, end
, &end_oid
)) {
297 show_rev(NORMAL
, &end_oid
, end
);
298 show_rev(symmetric
? NORMAL
: REVERSED
, &start_oid
, start
);
300 struct commit_list
*exclude
;
301 struct commit
*a
, *b
;
302 a
= lookup_commit_reference(the_repository
, &start_oid
);
303 b
= lookup_commit_reference(the_repository
, &end_oid
);
308 exclude
= repo_get_merge_bases(the_repository
, a
, b
);
310 struct commit
*commit
= pop_commit(&exclude
);
311 show_rev(REVERSED
, &commit
->object
.oid
, NULL
);
321 static int try_parent_shorthands(const char *arg
)
324 struct object_id oid
;
325 struct commit
*commit
;
326 struct commit_list
*parents
;
329 int include_parents
= 0;
330 int exclude_parent
= 0;
332 if ((dotdot
= strstr(arg
, "^!"))) {
336 } else if ((dotdot
= strstr(arg
, "^@"))) {
340 } else if ((dotdot
= strstr(arg
, "^-"))) {
346 exclude_parent
= strtoul(dotdot
+ 2, &end
, 10);
347 if (*end
!= '\0' || !exclude_parent
)
354 if (repo_get_oid_committish(the_repository
, arg
, &oid
) ||
355 !(commit
= lookup_commit_reference(the_repository
, &oid
))) {
360 if (exclude_parent
&&
361 exclude_parent
> commit_list_count(commit
->parents
)) {
367 show_rev(NORMAL
, &oid
, arg
);
368 for (parents
= commit
->parents
, parent_number
= 1;
370 parents
= parents
->next
, parent_number
++) {
373 if (exclude_parent
&& parent_number
!= exclude_parent
)
377 name
= xstrfmt("%s^%d", arg
, parent_number
);
378 show_rev(include_parents
? NORMAL
: REVERSED
,
379 &parents
->item
->object
.oid
, name
);
387 static int parseopt_dump(const struct option
*o
, const char *arg
, int unset
)
389 struct strbuf
*parsed
= o
->value
;
391 strbuf_addf(parsed
, " --no-%s", o
->long_name
);
392 else if (o
->short_name
&& (o
->long_name
== NULL
|| !stuck_long
))
393 strbuf_addf(parsed
, " -%c", o
->short_name
);
395 strbuf_addf(parsed
, " --%s", o
->long_name
);
398 strbuf_addch(parsed
, ' ');
399 else if (o
->long_name
)
400 strbuf_addch(parsed
, '=');
401 sq_quote_buf(parsed
, arg
);
406 static const char *skipspaces(const char *s
)
413 static char *findspace(const char *s
)
421 static int cmd_parseopt(int argc
, const char **argv
, const char *prefix
)
423 static int keep_dashdash
= 0, stop_at_non_option
= 0;
424 static char const * const parseopt_usage
[] = {
425 N_("git rev-parse --parseopt [<options>] -- [<args>...]"),
428 static struct option parseopt_opts
[] = {
429 OPT_BOOL(0, "keep-dashdash", &keep_dashdash
,
430 N_("keep the `--` passed as an arg")),
431 OPT_BOOL(0, "stop-at-non-option", &stop_at_non_option
,
432 N_("stop parsing after the "
433 "first non-option argument")),
434 OPT_BOOL(0, "stuck-long", &stuck_long
,
435 N_("output in stuck long form")),
438 static const char * const flag_chars
= "*=?!";
440 struct strbuf sb
= STRBUF_INIT
, parsed
= STRBUF_INIT
;
441 const char **usage
= NULL
;
442 struct option
*opts
= NULL
;
443 int onb
= 0, osz
= 0, unb
= 0, usz
= 0;
445 strbuf_addstr(&parsed
, "set --");
446 argc
= parse_options(argc
, argv
, prefix
, parseopt_opts
, parseopt_usage
,
447 PARSE_OPT_KEEP_DASHDASH
);
448 if (argc
< 1 || strcmp(argv
[0], "--"))
449 usage_with_options(parseopt_usage
, parseopt_opts
);
451 /* get the usage up to the first line with a -- on it */
453 if (strbuf_getline(&sb
, stdin
) == EOF
)
454 die(_("premature end of input"));
455 ALLOC_GROW(usage
, unb
+ 1, usz
);
456 if (!strcmp("--", sb
.buf
)) {
458 die(_("no usage string given before the `--' separator"));
462 usage
[unb
++] = strbuf_detach(&sb
, NULL
);
465 /* parse: (<short>|<short>,<long>|<long>)[*=?!]*<arghint>? SP+ <help> */
466 while (strbuf_getline(&sb
, stdin
) != EOF
) {
474 ALLOC_GROW(opts
, onb
+ 1, osz
);
475 memset(opts
+ onb
, 0, sizeof(opts
[onb
]));
478 help
= findspace(sb
.buf
);
479 if (!help
|| sb
.buf
== help
) {
480 o
->type
= OPTION_GROUP
;
481 o
->help
= xstrdup(skipspaces(sb
.buf
));
487 o
->type
= OPTION_CALLBACK
;
488 o
->help
= xstrdup(skipspaces(help
+1));
490 o
->flags
= PARSE_OPT_NOARG
;
491 o
->callback
= &parseopt_dump
;
494 s
= strpbrk(sb
.buf
, flag_chars
);
499 die(_("missing opt-spec before option flags"));
501 if (s
- sb
.buf
== 1) /* short option only */
502 o
->short_name
= *sb
.buf
;
503 else if (sb
.buf
[1] != ',') /* long option only */
504 o
->long_name
= xmemdupz(sb
.buf
, s
- sb
.buf
);
506 o
->short_name
= *sb
.buf
;
507 o
->long_name
= xmemdupz(sb
.buf
+ 2, s
- sb
.buf
- 2);
514 o
->flags
&= ~PARSE_OPT_NOARG
;
517 o
->flags
&= ~PARSE_OPT_NOARG
;
518 o
->flags
|= PARSE_OPT_OPTARG
;
521 o
->flags
|= PARSE_OPT_NONEG
;
524 o
->flags
|= PARSE_OPT_HIDDEN
;
532 o
->argh
= xmemdupz(s
, help
- s
);
536 /* put an OPT_END() */
537 ALLOC_GROW(opts
, onb
+ 1, osz
);
538 memset(opts
+ onb
, 0, sizeof(opts
[onb
]));
539 argc
= parse_options(argc
, argv
, prefix
, opts
, usage
,
540 (keep_dashdash
? PARSE_OPT_KEEP_DASHDASH
: 0) |
541 (stop_at_non_option
? PARSE_OPT_STOP_AT_NON_OPTION
: 0) |
542 PARSE_OPT_SHELL_EVAL
);
544 strbuf_addstr(&parsed
, " --");
545 sq_quote_argv(&parsed
, argv
);
547 strbuf_release(&parsed
);
551 static int cmd_sq_quote(int argc
, const char **argv
)
553 struct strbuf buf
= STRBUF_INIT
;
556 sq_quote_argv(&buf
, argv
);
557 printf("%s\n", buf
.buf
);
558 strbuf_release(&buf
);
563 static void die_no_single_rev(int quiet
)
568 die(_("Needed a single revision"));
571 static const char builtin_rev_parse_usage
[] =
572 N_("git rev-parse --parseopt [<options>] -- [<args>...]\n"
573 " or: git rev-parse --sq-quote [<arg>...]\n"
574 " or: git rev-parse [<options>] [<arg>...]\n"
576 "Run \"git rev-parse --parseopt -h\" for more information on the first usage.");
579 * Parse "opt" or "opt=<value>", setting value respectively to either
580 * NULL or the string after "=".
582 static int opt_with_value(const char *arg
, const char *opt
, const char **value
)
584 if (skip_prefix(arg
, opt
, &arg
)) {
597 static void handle_ref_opt(const char *pattern
, const char *prefix
)
600 for_each_glob_ref_in(show_reference
, pattern
, prefix
, NULL
);
602 for_each_ref_in(prefix
, show_reference
, NULL
);
603 clear_ref_exclusions(&ref_excludes
);
607 /* We would like a relative path. */
609 /* We would like a canonical absolute path. */
611 /* We would like the default behavior. */
616 /* Our default is a relative path. */
618 /* Our default is a relative path if there's a shared root. */
619 DEFAULT_RELATIVE_IF_SHARED
,
620 /* Our default is a canonical absolute path. */
622 /* Our default is not to modify the item. */
626 static void print_path(const char *path
, const char *prefix
, enum format_type format
, enum default_type def
)
630 * We don't ever produce a relative path if prefix is NULL, so set the
631 * prefix to the current directory so that we can produce a relative
632 * path whenever possible. If we're using RELATIVE_IF_SHARED mode, then
633 * we want an absolute path unless the two share a common prefix, so don't
634 * set it in that case, since doing so causes a relative path to always
635 * be produced if possible.
637 if (!prefix
&& (format
!= FORMAT_DEFAULT
|| def
!= DEFAULT_RELATIVE_IF_SHARED
))
638 prefix
= cwd
= xgetcwd();
639 if (format
== FORMAT_DEFAULT
&& def
== DEFAULT_UNMODIFIED
) {
641 } else if (format
== FORMAT_RELATIVE
||
642 (format
== FORMAT_DEFAULT
&& def
== DEFAULT_RELATIVE
)) {
644 * In order for relative_path to work as expected, we need to
645 * make sure that both paths are absolute paths. If we don't,
646 * we can end up with an unexpected absolute path that the user
649 struct strbuf buf
= STRBUF_INIT
, realbuf
= STRBUF_INIT
, prefixbuf
= STRBUF_INIT
;
650 if (!is_absolute_path(path
)) {
651 strbuf_realpath_forgiving(&realbuf
, path
, 1);
654 if (!is_absolute_path(prefix
)) {
655 strbuf_realpath_forgiving(&prefixbuf
, prefix
, 1);
656 prefix
= prefixbuf
.buf
;
658 puts(relative_path(path
, prefix
, &buf
));
659 strbuf_release(&buf
);
660 strbuf_release(&realbuf
);
661 strbuf_release(&prefixbuf
);
662 } else if (format
== FORMAT_DEFAULT
&& def
== DEFAULT_RELATIVE_IF_SHARED
) {
663 struct strbuf buf
= STRBUF_INIT
;
664 puts(relative_path(path
, prefix
, &buf
));
665 strbuf_release(&buf
);
667 struct strbuf buf
= STRBUF_INIT
;
668 strbuf_realpath_forgiving(&buf
, path
, 1);
670 strbuf_release(&buf
);
675 int cmd_rev_parse(int argc
, const char **argv
, const char *prefix
)
677 int i
, as_is
= 0, verify
= 0, quiet
= 0, revs_count
= 0, type
= 0;
678 int did_repo_setup
= 0;
679 int has_dashdash
= 0;
680 int output_prefix
= 0;
681 struct object_id oid
;
682 unsigned int flags
= 0;
683 const char *name
= NULL
;
684 struct object_context unused
;
685 struct strbuf buf
= STRBUF_INIT
;
686 const int hexsz
= the_hash_algo
->hexsz
;
687 int seen_end_of_options
= 0;
688 enum format_type format
= FORMAT_DEFAULT
;
690 if (argc
> 1 && !strcmp("--parseopt", argv
[1]))
691 return cmd_parseopt(argc
- 1, argv
+ 1, prefix
);
693 if (argc
> 1 && !strcmp("--sq-quote", argv
[1]))
694 return cmd_sq_quote(argc
- 2, argv
+ 2);
696 if (argc
> 1 && !strcmp("-h", argv
[1]))
697 usage(builtin_rev_parse_usage
);
699 for (i
= 1; i
< argc
; i
++) {
700 if (!strcmp(argv
[i
], "--")) {
706 /* No options; just report on whether we're in a git repo or not. */
708 setup_git_directory();
709 git_config(git_default_config
, NULL
);
713 for (i
= 1; i
< argc
; i
++) {
714 const char *arg
= argv
[i
];
717 if (show_file(arg
, output_prefix
) && as_is
< 2)
718 verify_filename(prefix
, arg
, 0);
722 if (!seen_end_of_options
) {
723 if (!strcmp(arg
, "--local-env-vars")) {
725 for (i
= 0; local_repo_env
[i
]; i
++)
726 printf("%s\n", local_repo_env
[i
]);
729 if (!strcmp(arg
, "--resolve-git-dir")) {
730 const char *gitdir
= argv
[++i
];
732 die(_("--resolve-git-dir requires an argument"));
733 gitdir
= resolve_gitdir(gitdir
);
735 die(_("not a gitdir '%s'"), argv
[i
]);
741 /* The rest of the options require a git repository. */
742 if (!did_repo_setup
) {
743 prefix
= setup_git_directory();
744 git_config(git_default_config
, NULL
);
747 prepare_repo_settings(the_repository
);
748 the_repository
->settings
.command_requires_full_index
= 0;
751 if (!strcmp(arg
, "--")) {
753 /* Pass on the "--" if we show anything but files.. */
754 if (filter
& (DO_FLAGS
| DO_REVS
))
759 if (!seen_end_of_options
&& *arg
== '-') {
760 if (!strcmp(arg
, "--git-path")) {
762 die(_("--git-path requires an argument"));
764 print_path(git_path("%s", argv
[i
+ 1]), prefix
,
766 DEFAULT_RELATIVE_IF_SHARED
);
770 if (!strcmp(arg
,"-n")) {
772 die(_("-n requires an argument"));
773 if ((filter
& DO_FLAGS
) && (filter
& DO_REVS
)) {
779 if (starts_with(arg
, "-n")) {
780 if ((filter
& DO_FLAGS
) && (filter
& DO_REVS
))
784 if (opt_with_value(arg
, "--path-format", &arg
)) {
786 die(_("--path-format requires an argument"));
787 if (!strcmp(arg
, "absolute")) {
788 format
= FORMAT_CANONICAL
;
789 } else if (!strcmp(arg
, "relative")) {
790 format
= FORMAT_RELATIVE
;
792 die(_("unknown argument to --path-format: %s"), arg
);
796 if (!strcmp(arg
, "--default")) {
799 die(_("--default requires an argument"));
802 if (!strcmp(arg
, "--prefix")) {
805 die(_("--prefix requires an argument"));
806 startup_info
->prefix
= prefix
;
810 if (!strcmp(arg
, "--revs-only")) {
814 if (!strcmp(arg
, "--no-revs")) {
818 if (!strcmp(arg
, "--flags")) {
819 filter
&= ~DO_NONFLAGS
;
822 if (!strcmp(arg
, "--no-flags")) {
826 if (!strcmp(arg
, "--verify")) {
827 filter
&= ~(DO_FLAGS
|DO_NOREV
);
831 if (!strcmp(arg
, "--quiet") || !strcmp(arg
, "-q")) {
833 flags
|= GET_OID_QUIETLY
;
836 if (opt_with_value(arg
, "--short", &arg
)) {
837 filter
&= ~(DO_FLAGS
|DO_NOREV
);
839 abbrev
= DEFAULT_ABBREV
;
842 abbrev
= strtoul(arg
, NULL
, 10);
843 if (abbrev
< MINIMUM_ABBREV
)
844 abbrev
= MINIMUM_ABBREV
;
845 else if (hexsz
<= abbrev
)
849 if (!strcmp(arg
, "--sq")) {
853 if (!strcmp(arg
, "--not")) {
854 show_type
^= REVERSED
;
857 if (!strcmp(arg
, "--symbolic")) {
858 symbolic
= SHOW_SYMBOLIC_ASIS
;
861 if (!strcmp(arg
, "--symbolic-full-name")) {
862 symbolic
= SHOW_SYMBOLIC_FULL
;
865 if (opt_with_value(arg
, "--abbrev-ref", &arg
)) {
867 abbrev_ref_strict
= warn_ambiguous_refs
;
869 if (!strcmp(arg
, "strict"))
870 abbrev_ref_strict
= 1;
871 else if (!strcmp(arg
, "loose"))
872 abbrev_ref_strict
= 0;
874 die(_("unknown mode for --abbrev-ref: %s"),
879 if (!strcmp(arg
, "--all")) {
880 for_each_ref(show_reference
, NULL
);
881 clear_ref_exclusions(&ref_excludes
);
884 if (skip_prefix(arg
, "--disambiguate=", &arg
)) {
885 repo_for_each_abbrev(the_repository
, arg
,
889 if (!strcmp(arg
, "--bisect")) {
890 for_each_fullref_in("refs/bisect/bad", show_reference
, NULL
);
891 for_each_fullref_in("refs/bisect/good", anti_reference
, NULL
);
894 if (opt_with_value(arg
, "--branches", &arg
)) {
895 if (ref_excludes
.hidden_refs_configured
)
896 return error(_("options '%s' and '%s' cannot be used together"),
897 "--exclude-hidden", "--branches");
898 handle_ref_opt(arg
, "refs/heads/");
901 if (opt_with_value(arg
, "--tags", &arg
)) {
902 if (ref_excludes
.hidden_refs_configured
)
903 return error(_("options '%s' and '%s' cannot be used together"),
904 "--exclude-hidden", "--tags");
905 handle_ref_opt(arg
, "refs/tags/");
908 if (skip_prefix(arg
, "--glob=", &arg
)) {
909 handle_ref_opt(arg
, NULL
);
912 if (opt_with_value(arg
, "--remotes", &arg
)) {
913 if (ref_excludes
.hidden_refs_configured
)
914 return error(_("options '%s' and '%s' cannot be used together"),
915 "--exclude-hidden", "--remotes");
916 handle_ref_opt(arg
, "refs/remotes/");
919 if (skip_prefix(arg
, "--exclude=", &arg
)) {
920 add_ref_exclusion(&ref_excludes
, arg
);
923 if (skip_prefix(arg
, "--exclude-hidden=", &arg
)) {
924 exclude_hidden_refs(&ref_excludes
, arg
);
927 if (!strcmp(arg
, "--show-toplevel")) {
928 const char *work_tree
= get_git_work_tree();
930 print_path(work_tree
, prefix
, format
, DEFAULT_UNMODIFIED
);
932 die(_("this operation must be run in a work tree"));
935 if (!strcmp(arg
, "--show-superproject-working-tree")) {
936 struct strbuf superproject
= STRBUF_INIT
;
937 if (get_superproject_working_tree(&superproject
))
938 print_path(superproject
.buf
, prefix
, format
, DEFAULT_UNMODIFIED
);
939 strbuf_release(&superproject
);
942 if (!strcmp(arg
, "--show-prefix")) {
949 if (!strcmp(arg
, "--show-cdup")) {
950 const char *pfx
= prefix
;
951 if (!is_inside_work_tree()) {
952 const char *work_tree
=
955 printf("%s\n", work_tree
);
959 pfx
= strchr(pfx
, '/');
968 if (!strcmp(arg
, "--git-dir") ||
969 !strcmp(arg
, "--absolute-git-dir")) {
970 const char *gitdir
= getenv(GIT_DIR_ENVIRONMENT
);
973 enum format_type wanted
= format
;
974 if (arg
[2] == 'g') { /* --git-dir */
976 print_path(gitdir
, prefix
, format
, DEFAULT_UNMODIFIED
);
980 print_path(".git", prefix
, format
, DEFAULT_UNMODIFIED
);
983 } else { /* --absolute-git-dir */
984 wanted
= FORMAT_CANONICAL
;
985 if (!gitdir
&& !prefix
)
988 struct strbuf realpath
= STRBUF_INIT
;
989 strbuf_realpath(&realpath
, gitdir
, 1);
991 strbuf_release(&realpath
);
998 strbuf_addf(&buf
, "%s%s.git", cwd
, len
&& cwd
[len
-1] != '/' ? "/" : "");
1000 print_path(buf
.buf
, prefix
, wanted
, DEFAULT_CANONICAL
);
1003 if (!strcmp(arg
, "--git-common-dir")) {
1004 print_path(get_git_common_dir(), prefix
, format
, DEFAULT_RELATIVE_IF_SHARED
);
1007 if (!strcmp(arg
, "--is-inside-git-dir")) {
1008 printf("%s\n", is_inside_git_dir() ? "true"
1012 if (!strcmp(arg
, "--is-inside-work-tree")) {
1013 printf("%s\n", is_inside_work_tree() ? "true"
1017 if (!strcmp(arg
, "--is-bare-repository")) {
1018 printf("%s\n", is_bare_repository() ? "true"
1022 if (!strcmp(arg
, "--is-shallow-repository")) {
1024 is_repository_shallow(the_repository
) ? "true"
1028 if (!strcmp(arg
, "--shared-index-path")) {
1029 if (repo_read_index(the_repository
) < 0)
1030 die(_("Could not read the index"));
1031 if (the_index
.split_index
) {
1032 const struct object_id
*oid
= &the_index
.split_index
->base_oid
;
1033 const char *path
= git_path("sharedindex.%s", oid_to_hex(oid
));
1034 print_path(path
, prefix
, format
, DEFAULT_RELATIVE
);
1038 if (skip_prefix(arg
, "--since=", &arg
)) {
1039 show_datestring("--max-age=", arg
);
1042 if (skip_prefix(arg
, "--after=", &arg
)) {
1043 show_datestring("--max-age=", arg
);
1046 if (skip_prefix(arg
, "--before=", &arg
)) {
1047 show_datestring("--min-age=", arg
);
1050 if (skip_prefix(arg
, "--until=", &arg
)) {
1051 show_datestring("--min-age=", arg
);
1054 if (opt_with_value(arg
, "--show-object-format", &arg
)) {
1055 const char *val
= arg
? arg
: "storage";
1057 if (strcmp(val
, "storage") &&
1058 strcmp(val
, "input") &&
1059 strcmp(val
, "output"))
1060 die(_("unknown mode for --show-object-format: %s"),
1062 puts(the_hash_algo
->name
);
1065 if (!strcmp(arg
, "--show-ref-format")) {
1066 puts(ref_storage_format_to_name(the_repository
->ref_storage_format
));
1069 if (!strcmp(arg
, "--end-of-options")) {
1070 seen_end_of_options
= 1;
1071 if (filter
& (DO_FLAGS
| DO_REVS
))
1075 if (show_flag(arg
) && verify
)
1076 die_no_single_rev(quiet
);
1080 /* Not a flag argument */
1081 if (try_difference(arg
))
1083 if (try_parent_shorthands(arg
))
1091 if (!get_oid_with_context(the_repository
, name
,
1092 flags
, &oid
, &unused
)) {
1096 show_rev(type
, &oid
, name
);
1100 die_no_single_rev(quiet
);
1102 die(_("bad revision '%s'"), arg
);
1104 if (!show_file(arg
, output_prefix
))
1106 verify_filename(prefix
, arg
, 1);
1108 strbuf_release(&buf
);
1110 if (revs_count
== 1) {
1111 show_rev(type
, &oid
, name
);
1113 } else if (revs_count
== 0 && show_default())
1115 die_no_single_rev(quiet
);