4 * Copyright (C) Linus Torvalds, 2005
6 #define USE_THE_INDEX_VARIABLE
12 #include "environment.h"
18 #include "parse-options.h"
22 #include "split-index.h"
23 #include "submodule.h"
24 #include "commit-reach.h"
31 static int filter
= ~0;
33 static const char *def
;
37 static int show_type
= NORMAL
;
39 #define SHOW_SYMBOLIC_ASIS 1
40 #define SHOW_SYMBOLIC_FULL 2
43 static int abbrev_ref
;
44 static int abbrev_ref_strict
;
47 static int stuck_long
;
48 static struct ref_exclusions ref_excludes
= REF_EXCLUSIONS_INIT
;
51 * Some arguments are relevant "revision" arguments,
52 * others are about output format or other details.
53 * This sorts it all out.
55 static int is_rev_argument(const char *arg
)
57 static const char *rev_args
[] = {
88 const char **p
= rev_args
;
90 /* accept -<digit>, like traditional "head" */
91 if ((*arg
== '-') && isdigit(arg
[1]))
95 const char *str
= *p
++;
100 if (!strcmp(arg
, str
) ||
101 (str
[len
-1] == '=' && !strncmp(arg
, str
, len
)))
106 /* Output argument as a string, either SQ or normal */
107 static void show(const char *arg
)
113 while ((ch
= *arg
++)) {
115 fputs("'\\'", stdout
);
125 /* Like show(), but with a negation prefix according to type */
126 static void show_with_type(int type
, const char *arg
)
128 if (type
!= show_type
)
133 /* Output a revision, only if filter allows it */
134 static void show_rev(int type
, const struct object_id
*oid
, const char *name
)
136 if (!(filter
& DO_REVS
))
140 if ((symbolic
|| abbrev_ref
) && name
) {
141 if (symbolic
== SHOW_SYMBOLIC_FULL
|| abbrev_ref
) {
142 struct object_id discard
;
145 switch (repo_dwim_ref(the_repository
, name
,
146 strlen(name
), &discard
, &full
,
150 * Not found -- not a ref. We could
151 * emit "name" here, but symbolic-full
152 * users are interested in finding the
153 * refs spelled in full, and they would
154 * need to filter non-refs if we did so.
159 full
= shorten_unambiguous_ref(full
,
161 show_with_type(type
, full
);
163 default: /* ambiguous */
164 error("refname '%s' is ambiguous", name
);
169 show_with_type(type
, name
);
174 repo_find_unique_abbrev(the_repository
, oid
, abbrev
));
176 show_with_type(type
, oid_to_hex(oid
));
179 /* Output a flag, only if filter allows it. */
180 static int show_flag(const char *arg
)
182 if (!(filter
& DO_FLAGS
))
184 if (filter
& (is_rev_argument(arg
) ? DO_REVS
: DO_NOREV
)) {
191 static int show_default(void)
196 struct object_id oid
;
199 if (!repo_get_oid(the_repository
, s
, &oid
)) {
200 show_rev(NORMAL
, &oid
, s
);
207 static int show_reference(const char *refname
, const struct object_id
*oid
,
208 int flag UNUSED
, void *cb_data UNUSED
)
210 if (ref_excluded(&ref_excludes
, refname
))
212 show_rev(NORMAL
, oid
, refname
);
216 static int anti_reference(const char *refname
, const struct object_id
*oid
,
217 int flag UNUSED
, void *cb_data UNUSED
)
219 show_rev(REVERSED
, oid
, refname
);
223 static int show_abbrev(const struct object_id
*oid
, void *cb_data
)
225 show_rev(NORMAL
, oid
, NULL
);
229 static void show_datestring(const char *flag
, const char *datestr
)
233 /* date handling requires both flags and revs */
234 if ((filter
& (DO_FLAGS
| DO_REVS
)) != (DO_FLAGS
| DO_REVS
))
236 buffer
= xstrfmt("%s%"PRItime
, flag
, approxidate(datestr
));
241 static int show_file(const char *arg
, int output_prefix
)
244 if ((filter
& (DO_NONFLAGS
|DO_NOREV
)) == (DO_NONFLAGS
|DO_NOREV
)) {
246 const char *prefix
= startup_info
->prefix
;
247 char *fname
= prefix_filename(prefix
, arg
);
257 static int try_difference(const char *arg
)
260 struct object_id start_oid
;
261 struct object_id end_oid
;
265 static const char head_by_default
[] = "HEAD";
267 if (!(dotdot
= strstr(arg
, "..")))
271 symmetric
= (*end
== '.');
277 end
= head_by_default
;
279 start
= head_by_default
;
281 if (start
== head_by_default
&& end
== head_by_default
&&
284 * Just ".."? That is not a range but the
285 * pathspec for the parent directory.
291 if (!repo_get_oid_committish(the_repository
, start
, &start_oid
) && !repo_get_oid_committish(the_repository
, end
, &end_oid
)) {
292 show_rev(NORMAL
, &end_oid
, end
);
293 show_rev(symmetric
? NORMAL
: REVERSED
, &start_oid
, start
);
295 struct commit_list
*exclude
;
296 struct commit
*a
, *b
;
297 a
= lookup_commit_reference(the_repository
, &start_oid
);
298 b
= lookup_commit_reference(the_repository
, &end_oid
);
303 exclude
= repo_get_merge_bases(the_repository
, a
, b
);
305 struct commit
*commit
= pop_commit(&exclude
);
306 show_rev(REVERSED
, &commit
->object
.oid
, NULL
);
316 static int try_parent_shorthands(const char *arg
)
319 struct object_id oid
;
320 struct commit
*commit
;
321 struct commit_list
*parents
;
324 int include_parents
= 0;
325 int exclude_parent
= 0;
327 if ((dotdot
= strstr(arg
, "^!"))) {
331 } else if ((dotdot
= strstr(arg
, "^@"))) {
335 } else if ((dotdot
= strstr(arg
, "^-"))) {
341 exclude_parent
= strtoul(dotdot
+ 2, &end
, 10);
342 if (*end
!= '\0' || !exclude_parent
)
349 if (repo_get_oid_committish(the_repository
, arg
, &oid
) ||
350 !(commit
= lookup_commit_reference(the_repository
, &oid
))) {
355 if (exclude_parent
&&
356 exclude_parent
> commit_list_count(commit
->parents
)) {
362 show_rev(NORMAL
, &oid
, arg
);
363 for (parents
= commit
->parents
, parent_number
= 1;
365 parents
= parents
->next
, parent_number
++) {
368 if (exclude_parent
&& parent_number
!= exclude_parent
)
372 name
= xstrfmt("%s^%d", arg
, parent_number
);
373 show_rev(include_parents
? NORMAL
: REVERSED
,
374 &parents
->item
->object
.oid
, name
);
382 static int parseopt_dump(const struct option
*o
, const char *arg
, int unset
)
384 struct strbuf
*parsed
= o
->value
;
386 strbuf_addf(parsed
, " --no-%s", o
->long_name
);
387 else if (o
->short_name
&& (o
->long_name
== NULL
|| !stuck_long
))
388 strbuf_addf(parsed
, " -%c", o
->short_name
);
390 strbuf_addf(parsed
, " --%s", o
->long_name
);
393 strbuf_addch(parsed
, ' ');
394 else if (o
->long_name
)
395 strbuf_addch(parsed
, '=');
396 sq_quote_buf(parsed
, arg
);
401 static const char *skipspaces(const char *s
)
408 static char *findspace(const char *s
)
416 static int cmd_parseopt(int argc
, const char **argv
, const char *prefix
)
418 static int keep_dashdash
= 0, stop_at_non_option
= 0;
419 static char const * const parseopt_usage
[] = {
420 N_("git rev-parse --parseopt [<options>] -- [<args>...]"),
423 static struct option parseopt_opts
[] = {
424 OPT_BOOL(0, "keep-dashdash", &keep_dashdash
,
425 N_("keep the `--` passed as an arg")),
426 OPT_BOOL(0, "stop-at-non-option", &stop_at_non_option
,
427 N_("stop parsing after the "
428 "first non-option argument")),
429 OPT_BOOL(0, "stuck-long", &stuck_long
,
430 N_("output in stuck long form")),
433 static const char * const flag_chars
= "*=?!";
435 struct strbuf sb
= STRBUF_INIT
, parsed
= STRBUF_INIT
;
436 const char **usage
= NULL
;
437 struct option
*opts
= NULL
;
438 int onb
= 0, osz
= 0, unb
= 0, usz
= 0;
440 strbuf_addstr(&parsed
, "set --");
441 argc
= parse_options(argc
, argv
, prefix
, parseopt_opts
, parseopt_usage
,
442 PARSE_OPT_KEEP_DASHDASH
);
443 if (argc
< 1 || strcmp(argv
[0], "--"))
444 usage_with_options(parseopt_usage
, parseopt_opts
);
446 /* get the usage up to the first line with a -- on it */
448 if (strbuf_getline(&sb
, stdin
) == EOF
)
449 die(_("premature end of input"));
450 ALLOC_GROW(usage
, unb
+ 1, usz
);
451 if (!strcmp("--", sb
.buf
)) {
453 die(_("no usage string given before the `--' separator"));
457 usage
[unb
++] = strbuf_detach(&sb
, NULL
);
460 /* parse: (<short>|<short>,<long>|<long>)[*=?!]*<arghint>? SP+ <help> */
461 while (strbuf_getline(&sb
, stdin
) != EOF
) {
469 ALLOC_GROW(opts
, onb
+ 1, osz
);
470 memset(opts
+ onb
, 0, sizeof(opts
[onb
]));
473 help
= findspace(sb
.buf
);
474 if (!help
|| sb
.buf
== help
) {
475 o
->type
= OPTION_GROUP
;
476 o
->help
= xstrdup(skipspaces(sb
.buf
));
482 o
->type
= OPTION_CALLBACK
;
483 o
->help
= xstrdup(skipspaces(help
+1));
485 o
->flags
= PARSE_OPT_NOARG
;
486 o
->callback
= &parseopt_dump
;
489 s
= strpbrk(sb
.buf
, flag_chars
);
494 die(_("missing opt-spec before option flags"));
496 if (s
- sb
.buf
== 1) /* short option only */
497 o
->short_name
= *sb
.buf
;
498 else if (sb
.buf
[1] != ',') /* long option only */
499 o
->long_name
= xmemdupz(sb
.buf
, s
- sb
.buf
);
501 o
->short_name
= *sb
.buf
;
502 o
->long_name
= xmemdupz(sb
.buf
+ 2, s
- sb
.buf
- 2);
509 o
->flags
&= ~PARSE_OPT_NOARG
;
512 o
->flags
&= ~PARSE_OPT_NOARG
;
513 o
->flags
|= PARSE_OPT_OPTARG
;
516 o
->flags
|= PARSE_OPT_NONEG
;
519 o
->flags
|= PARSE_OPT_HIDDEN
;
527 o
->argh
= xmemdupz(s
, help
- s
);
531 /* put an OPT_END() */
532 ALLOC_GROW(opts
, onb
+ 1, osz
);
533 memset(opts
+ onb
, 0, sizeof(opts
[onb
]));
534 argc
= parse_options(argc
, argv
, prefix
, opts
, usage
,
535 (keep_dashdash
? PARSE_OPT_KEEP_DASHDASH
: 0) |
536 (stop_at_non_option
? PARSE_OPT_STOP_AT_NON_OPTION
: 0) |
537 PARSE_OPT_SHELL_EVAL
);
539 strbuf_addstr(&parsed
, " --");
540 sq_quote_argv(&parsed
, argv
);
542 strbuf_release(&parsed
);
546 static int cmd_sq_quote(int argc
, const char **argv
)
548 struct strbuf buf
= STRBUF_INIT
;
551 sq_quote_argv(&buf
, argv
);
552 printf("%s\n", buf
.buf
);
553 strbuf_release(&buf
);
558 static void die_no_single_rev(int quiet
)
563 die(_("Needed a single revision"));
566 static const char builtin_rev_parse_usage
[] =
567 N_("git rev-parse --parseopt [<options>] -- [<args>...]\n"
568 " or: git rev-parse --sq-quote [<arg>...]\n"
569 " or: git rev-parse [<options>] [<arg>...]\n"
571 "Run \"git rev-parse --parseopt -h\" for more information on the first usage.");
574 * Parse "opt" or "opt=<value>", setting value respectively to either
575 * NULL or the string after "=".
577 static int opt_with_value(const char *arg
, const char *opt
, const char **value
)
579 if (skip_prefix(arg
, opt
, &arg
)) {
592 static void handle_ref_opt(const char *pattern
, const char *prefix
)
595 for_each_glob_ref_in(show_reference
, pattern
, prefix
, NULL
);
597 for_each_ref_in(prefix
, show_reference
, NULL
);
598 clear_ref_exclusions(&ref_excludes
);
602 /* We would like a relative path. */
604 /* We would like a canonical absolute path. */
606 /* We would like the default behavior. */
611 /* Our default is a relative path. */
613 /* Our default is a relative path if there's a shared root. */
614 DEFAULT_RELATIVE_IF_SHARED
,
615 /* Our default is a canonical absolute path. */
617 /* Our default is not to modify the item. */
621 static void print_path(const char *path
, const char *prefix
, enum format_type format
, enum default_type def
)
625 * We don't ever produce a relative path if prefix is NULL, so set the
626 * prefix to the current directory so that we can produce a relative
627 * path whenever possible. If we're using RELATIVE_IF_SHARED mode, then
628 * we want an absolute path unless the two share a common prefix, so don't
629 * set it in that case, since doing so causes a relative path to always
630 * be produced if possible.
632 if (!prefix
&& (format
!= FORMAT_DEFAULT
|| def
!= DEFAULT_RELATIVE_IF_SHARED
))
633 prefix
= cwd
= xgetcwd();
634 if (format
== FORMAT_DEFAULT
&& def
== DEFAULT_UNMODIFIED
) {
636 } else if (format
== FORMAT_RELATIVE
||
637 (format
== FORMAT_DEFAULT
&& def
== DEFAULT_RELATIVE
)) {
639 * In order for relative_path to work as expected, we need to
640 * make sure that both paths are absolute paths. If we don't,
641 * we can end up with an unexpected absolute path that the user
644 struct strbuf buf
= STRBUF_INIT
, realbuf
= STRBUF_INIT
, prefixbuf
= STRBUF_INIT
;
645 if (!is_absolute_path(path
)) {
646 strbuf_realpath_forgiving(&realbuf
, path
, 1);
649 if (!is_absolute_path(prefix
)) {
650 strbuf_realpath_forgiving(&prefixbuf
, prefix
, 1);
651 prefix
= prefixbuf
.buf
;
653 puts(relative_path(path
, prefix
, &buf
));
654 strbuf_release(&buf
);
655 strbuf_release(&realbuf
);
656 strbuf_release(&prefixbuf
);
657 } else if (format
== FORMAT_DEFAULT
&& def
== DEFAULT_RELATIVE_IF_SHARED
) {
658 struct strbuf buf
= STRBUF_INIT
;
659 puts(relative_path(path
, prefix
, &buf
));
660 strbuf_release(&buf
);
662 struct strbuf buf
= STRBUF_INIT
;
663 strbuf_realpath_forgiving(&buf
, path
, 1);
665 strbuf_release(&buf
);
670 int cmd_rev_parse(int argc
, const char **argv
, const char *prefix
)
672 int i
, as_is
= 0, verify
= 0, quiet
= 0, revs_count
= 0, type
= 0;
673 int did_repo_setup
= 0;
674 int has_dashdash
= 0;
675 int output_prefix
= 0;
676 struct object_id oid
;
677 unsigned int flags
= 0;
678 const char *name
= NULL
;
679 struct object_context unused
;
680 struct strbuf buf
= STRBUF_INIT
;
681 const int hexsz
= the_hash_algo
->hexsz
;
682 int seen_end_of_options
= 0;
683 enum format_type format
= FORMAT_DEFAULT
;
685 if (argc
> 1 && !strcmp("--parseopt", argv
[1]))
686 return cmd_parseopt(argc
- 1, argv
+ 1, prefix
);
688 if (argc
> 1 && !strcmp("--sq-quote", argv
[1]))
689 return cmd_sq_quote(argc
- 2, argv
+ 2);
691 if (argc
> 1 && !strcmp("-h", argv
[1]))
692 usage(builtin_rev_parse_usage
);
694 for (i
= 1; i
< argc
; i
++) {
695 if (!strcmp(argv
[i
], "--")) {
701 /* No options; just report on whether we're in a git repo or not. */
703 setup_git_directory();
704 git_config(git_default_config
, NULL
);
708 for (i
= 1; i
< argc
; i
++) {
709 const char *arg
= argv
[i
];
712 if (show_file(arg
, output_prefix
) && as_is
< 2)
713 verify_filename(prefix
, arg
, 0);
717 if (!seen_end_of_options
) {
718 if (!strcmp(arg
, "--local-env-vars")) {
720 for (i
= 0; local_repo_env
[i
]; i
++)
721 printf("%s\n", local_repo_env
[i
]);
724 if (!strcmp(arg
, "--resolve-git-dir")) {
725 const char *gitdir
= argv
[++i
];
727 die(_("--resolve-git-dir requires an argument"));
728 gitdir
= resolve_gitdir(gitdir
);
730 die(_("not a gitdir '%s'"), argv
[i
]);
736 /* The rest of the options require a git repository. */
737 if (!did_repo_setup
) {
738 prefix
= setup_git_directory();
739 git_config(git_default_config
, NULL
);
742 prepare_repo_settings(the_repository
);
743 the_repository
->settings
.command_requires_full_index
= 0;
746 if (!strcmp(arg
, "--")) {
748 /* Pass on the "--" if we show anything but files.. */
749 if (filter
& (DO_FLAGS
| DO_REVS
))
754 if (!seen_end_of_options
&& *arg
== '-') {
755 if (!strcmp(arg
, "--git-path")) {
757 die(_("--git-path requires an argument"));
759 print_path(git_path("%s", argv
[i
+ 1]), prefix
,
761 DEFAULT_RELATIVE_IF_SHARED
);
765 if (!strcmp(arg
,"-n")) {
767 die(_("-n requires an argument"));
768 if ((filter
& DO_FLAGS
) && (filter
& DO_REVS
)) {
774 if (starts_with(arg
, "-n")) {
775 if ((filter
& DO_FLAGS
) && (filter
& DO_REVS
))
779 if (opt_with_value(arg
, "--path-format", &arg
)) {
781 die(_("--path-format requires an argument"));
782 if (!strcmp(arg
, "absolute")) {
783 format
= FORMAT_CANONICAL
;
784 } else if (!strcmp(arg
, "relative")) {
785 format
= FORMAT_RELATIVE
;
787 die(_("unknown argument to --path-format: %s"), arg
);
791 if (!strcmp(arg
, "--default")) {
794 die(_("--default requires an argument"));
797 if (!strcmp(arg
, "--prefix")) {
800 die(_("--prefix requires an argument"));
801 startup_info
->prefix
= prefix
;
805 if (!strcmp(arg
, "--revs-only")) {
809 if (!strcmp(arg
, "--no-revs")) {
813 if (!strcmp(arg
, "--flags")) {
814 filter
&= ~DO_NONFLAGS
;
817 if (!strcmp(arg
, "--no-flags")) {
821 if (!strcmp(arg
, "--verify")) {
822 filter
&= ~(DO_FLAGS
|DO_NOREV
);
826 if (!strcmp(arg
, "--quiet") || !strcmp(arg
, "-q")) {
828 flags
|= GET_OID_QUIETLY
;
831 if (opt_with_value(arg
, "--short", &arg
)) {
832 filter
&= ~(DO_FLAGS
|DO_NOREV
);
834 abbrev
= DEFAULT_ABBREV
;
837 abbrev
= strtoul(arg
, NULL
, 10);
838 if (abbrev
< MINIMUM_ABBREV
)
839 abbrev
= MINIMUM_ABBREV
;
840 else if (hexsz
<= abbrev
)
844 if (!strcmp(arg
, "--sq")) {
848 if (!strcmp(arg
, "--not")) {
849 show_type
^= REVERSED
;
852 if (!strcmp(arg
, "--symbolic")) {
853 symbolic
= SHOW_SYMBOLIC_ASIS
;
856 if (!strcmp(arg
, "--symbolic-full-name")) {
857 symbolic
= SHOW_SYMBOLIC_FULL
;
860 if (opt_with_value(arg
, "--abbrev-ref", &arg
)) {
862 abbrev_ref_strict
= warn_ambiguous_refs
;
864 if (!strcmp(arg
, "strict"))
865 abbrev_ref_strict
= 1;
866 else if (!strcmp(arg
, "loose"))
867 abbrev_ref_strict
= 0;
869 die(_("unknown mode for --abbrev-ref: %s"),
874 if (!strcmp(arg
, "--all")) {
875 for_each_ref(show_reference
, NULL
);
876 clear_ref_exclusions(&ref_excludes
);
879 if (skip_prefix(arg
, "--disambiguate=", &arg
)) {
880 repo_for_each_abbrev(the_repository
, arg
,
884 if (!strcmp(arg
, "--bisect")) {
885 for_each_fullref_in("refs/bisect/bad", show_reference
, NULL
);
886 for_each_fullref_in("refs/bisect/good", anti_reference
, NULL
);
889 if (opt_with_value(arg
, "--branches", &arg
)) {
890 if (ref_excludes
.hidden_refs_configured
)
891 return error(_("--exclude-hidden cannot be used together with --branches"));
892 handle_ref_opt(arg
, "refs/heads/");
895 if (opt_with_value(arg
, "--tags", &arg
)) {
896 if (ref_excludes
.hidden_refs_configured
)
897 return error(_("--exclude-hidden cannot be used together with --tags"));
898 handle_ref_opt(arg
, "refs/tags/");
901 if (skip_prefix(arg
, "--glob=", &arg
)) {
902 handle_ref_opt(arg
, NULL
);
905 if (opt_with_value(arg
, "--remotes", &arg
)) {
906 if (ref_excludes
.hidden_refs_configured
)
907 return error(_("--exclude-hidden cannot be used together with --remotes"));
908 handle_ref_opt(arg
, "refs/remotes/");
911 if (skip_prefix(arg
, "--exclude=", &arg
)) {
912 add_ref_exclusion(&ref_excludes
, arg
);
915 if (skip_prefix(arg
, "--exclude-hidden=", &arg
)) {
916 exclude_hidden_refs(&ref_excludes
, arg
);
919 if (!strcmp(arg
, "--show-toplevel")) {
920 const char *work_tree
= get_git_work_tree();
922 print_path(work_tree
, prefix
, format
, DEFAULT_UNMODIFIED
);
924 die(_("this operation must be run in a work tree"));
927 if (!strcmp(arg
, "--show-superproject-working-tree")) {
928 struct strbuf superproject
= STRBUF_INIT
;
929 if (get_superproject_working_tree(&superproject
))
930 print_path(superproject
.buf
, prefix
, format
, DEFAULT_UNMODIFIED
);
931 strbuf_release(&superproject
);
934 if (!strcmp(arg
, "--show-prefix")) {
941 if (!strcmp(arg
, "--show-cdup")) {
942 const char *pfx
= prefix
;
943 if (!is_inside_work_tree()) {
944 const char *work_tree
=
947 printf("%s\n", work_tree
);
951 pfx
= strchr(pfx
, '/');
960 if (!strcmp(arg
, "--git-dir") ||
961 !strcmp(arg
, "--absolute-git-dir")) {
962 const char *gitdir
= getenv(GIT_DIR_ENVIRONMENT
);
965 enum format_type wanted
= format
;
966 if (arg
[2] == 'g') { /* --git-dir */
968 print_path(gitdir
, prefix
, format
, DEFAULT_UNMODIFIED
);
972 print_path(".git", prefix
, format
, DEFAULT_UNMODIFIED
);
975 } else { /* --absolute-git-dir */
976 wanted
= FORMAT_CANONICAL
;
977 if (!gitdir
&& !prefix
)
980 struct strbuf realpath
= STRBUF_INIT
;
981 strbuf_realpath(&realpath
, gitdir
, 1);
983 strbuf_release(&realpath
);
990 strbuf_addf(&buf
, "%s%s.git", cwd
, len
&& cwd
[len
-1] != '/' ? "/" : "");
992 print_path(buf
.buf
, prefix
, wanted
, DEFAULT_CANONICAL
);
995 if (!strcmp(arg
, "--git-common-dir")) {
996 print_path(get_git_common_dir(), prefix
, format
, DEFAULT_RELATIVE_IF_SHARED
);
999 if (!strcmp(arg
, "--is-inside-git-dir")) {
1000 printf("%s\n", is_inside_git_dir() ? "true"
1004 if (!strcmp(arg
, "--is-inside-work-tree")) {
1005 printf("%s\n", is_inside_work_tree() ? "true"
1009 if (!strcmp(arg
, "--is-bare-repository")) {
1010 printf("%s\n", is_bare_repository() ? "true"
1014 if (!strcmp(arg
, "--is-shallow-repository")) {
1016 is_repository_shallow(the_repository
) ? "true"
1020 if (!strcmp(arg
, "--shared-index-path")) {
1021 if (repo_read_index(the_repository
) < 0)
1022 die(_("Could not read the index"));
1023 if (the_index
.split_index
) {
1024 const struct object_id
*oid
= &the_index
.split_index
->base_oid
;
1025 const char *path
= git_path("sharedindex.%s", oid_to_hex(oid
));
1026 print_path(path
, prefix
, format
, DEFAULT_RELATIVE
);
1030 if (skip_prefix(arg
, "--since=", &arg
)) {
1031 show_datestring("--max-age=", arg
);
1034 if (skip_prefix(arg
, "--after=", &arg
)) {
1035 show_datestring("--max-age=", arg
);
1038 if (skip_prefix(arg
, "--before=", &arg
)) {
1039 show_datestring("--min-age=", arg
);
1042 if (skip_prefix(arg
, "--until=", &arg
)) {
1043 show_datestring("--min-age=", arg
);
1046 if (opt_with_value(arg
, "--show-object-format", &arg
)) {
1047 const char *val
= arg
? arg
: "storage";
1049 if (strcmp(val
, "storage") &&
1050 strcmp(val
, "input") &&
1051 strcmp(val
, "output"))
1052 die(_("unknown mode for --show-object-format: %s"),
1054 puts(the_hash_algo
->name
);
1057 if (!strcmp(arg
, "--end-of-options")) {
1058 seen_end_of_options
= 1;
1059 if (filter
& (DO_FLAGS
| DO_REVS
))
1063 if (show_flag(arg
) && verify
)
1064 die_no_single_rev(quiet
);
1068 /* Not a flag argument */
1069 if (try_difference(arg
))
1071 if (try_parent_shorthands(arg
))
1079 if (!get_oid_with_context(the_repository
, name
,
1080 flags
, &oid
, &unused
)) {
1084 show_rev(type
, &oid
, name
);
1088 die_no_single_rev(quiet
);
1090 die(_("bad revision '%s'"), arg
);
1092 if (!show_file(arg
, output_prefix
))
1094 verify_filename(prefix
, arg
, 1);
1096 strbuf_release(&buf
);
1098 if (revs_count
== 1) {
1099 show_rev(type
, &oid
, name
);
1101 } else if (revs_count
== 0 && show_default())
1103 die_no_single_rev(quiet
);