4 * Copyright (C) Linus Torvalds, 2005
6 #define USE_THE_INDEX_VARIABLE
13 #include "parse-options.h"
16 #include "split-index.h"
17 #include "submodule.h"
18 #include "commit-reach.h"
25 static int filter
= ~0;
27 static const char *def
;
31 static int show_type
= NORMAL
;
33 #define SHOW_SYMBOLIC_ASIS 1
34 #define SHOW_SYMBOLIC_FULL 2
37 static int abbrev_ref
;
38 static int abbrev_ref_strict
;
41 static int stuck_long
;
42 static struct ref_exclusions ref_excludes
= REF_EXCLUSIONS_INIT
;
45 * Some arguments are relevant "revision" arguments,
46 * others are about output format or other details.
47 * This sorts it all out.
49 static int is_rev_argument(const char *arg
)
51 static const char *rev_args
[] = {
82 const char **p
= rev_args
;
84 /* accept -<digit>, like traditional "head" */
85 if ((*arg
== '-') && isdigit(arg
[1]))
89 const char *str
= *p
++;
94 if (!strcmp(arg
, str
) ||
95 (str
[len
-1] == '=' && !strncmp(arg
, str
, len
)))
100 /* Output argument as a string, either SQ or normal */
101 static void show(const char *arg
)
107 while ((ch
= *arg
++)) {
109 fputs("'\\'", stdout
);
119 /* Like show(), but with a negation prefix according to type */
120 static void show_with_type(int type
, const char *arg
)
122 if (type
!= show_type
)
127 /* Output a revision, only if filter allows it */
128 static void show_rev(int type
, const struct object_id
*oid
, const char *name
)
130 if (!(filter
& DO_REVS
))
134 if ((symbolic
|| abbrev_ref
) && name
) {
135 if (symbolic
== SHOW_SYMBOLIC_FULL
|| abbrev_ref
) {
136 struct object_id discard
;
139 switch (dwim_ref(name
, strlen(name
), &discard
, &full
, 0)) {
142 * Not found -- not a ref. We could
143 * emit "name" here, but symbolic-full
144 * users are interested in finding the
145 * refs spelled in full, and they would
146 * need to filter non-refs if we did so.
151 full
= shorten_unambiguous_ref(full
,
153 show_with_type(type
, full
);
155 default: /* ambiguous */
156 error("refname '%s' is ambiguous", name
);
161 show_with_type(type
, name
);
165 show_with_type(type
, find_unique_abbrev(oid
, abbrev
));
167 show_with_type(type
, oid_to_hex(oid
));
170 /* Output a flag, only if filter allows it. */
171 static int show_flag(const char *arg
)
173 if (!(filter
& DO_FLAGS
))
175 if (filter
& (is_rev_argument(arg
) ? DO_REVS
: DO_NOREV
)) {
182 static int show_default(void)
187 struct object_id oid
;
190 if (!get_oid(s
, &oid
)) {
191 show_rev(NORMAL
, &oid
, s
);
198 static int show_reference(const char *refname
, const struct object_id
*oid
,
199 int flag UNUSED
, void *cb_data UNUSED
)
201 if (ref_excluded(&ref_excludes
, refname
))
203 show_rev(NORMAL
, oid
, refname
);
207 static int anti_reference(const char *refname
, const struct object_id
*oid
,
208 int flag UNUSED
, void *cb_data UNUSED
)
210 show_rev(REVERSED
, oid
, refname
);
214 static int show_abbrev(const struct object_id
*oid
, void *cb_data
)
216 show_rev(NORMAL
, oid
, NULL
);
220 static void show_datestring(const char *flag
, const char *datestr
)
224 /* date handling requires both flags and revs */
225 if ((filter
& (DO_FLAGS
| DO_REVS
)) != (DO_FLAGS
| DO_REVS
))
227 buffer
= xstrfmt("%s%"PRItime
, flag
, approxidate(datestr
));
232 static int show_file(const char *arg
, int output_prefix
)
235 if ((filter
& (DO_NONFLAGS
|DO_NOREV
)) == (DO_NONFLAGS
|DO_NOREV
)) {
237 const char *prefix
= startup_info
->prefix
;
238 char *fname
= prefix_filename(prefix
, arg
);
248 static int try_difference(const char *arg
)
251 struct object_id start_oid
;
252 struct object_id end_oid
;
256 static const char head_by_default
[] = "HEAD";
258 if (!(dotdot
= strstr(arg
, "..")))
262 symmetric
= (*end
== '.');
268 end
= head_by_default
;
270 start
= head_by_default
;
272 if (start
== head_by_default
&& end
== head_by_default
&&
275 * Just ".."? That is not a range but the
276 * pathspec for the parent directory.
282 if (!get_oid_committish(start
, &start_oid
) && !get_oid_committish(end
, &end_oid
)) {
283 show_rev(NORMAL
, &end_oid
, end
);
284 show_rev(symmetric
? NORMAL
: REVERSED
, &start_oid
, start
);
286 struct commit_list
*exclude
;
287 struct commit
*a
, *b
;
288 a
= lookup_commit_reference(the_repository
, &start_oid
);
289 b
= lookup_commit_reference(the_repository
, &end_oid
);
294 exclude
= get_merge_bases(a
, b
);
296 struct commit
*commit
= pop_commit(&exclude
);
297 show_rev(REVERSED
, &commit
->object
.oid
, NULL
);
307 static int try_parent_shorthands(const char *arg
)
310 struct object_id oid
;
311 struct commit
*commit
;
312 struct commit_list
*parents
;
315 int include_parents
= 0;
316 int exclude_parent
= 0;
318 if ((dotdot
= strstr(arg
, "^!"))) {
322 } else if ((dotdot
= strstr(arg
, "^@"))) {
326 } else if ((dotdot
= strstr(arg
, "^-"))) {
332 exclude_parent
= strtoul(dotdot
+ 2, &end
, 10);
333 if (*end
!= '\0' || !exclude_parent
)
340 if (get_oid_committish(arg
, &oid
) ||
341 !(commit
= lookup_commit_reference(the_repository
, &oid
))) {
346 if (exclude_parent
&&
347 exclude_parent
> commit_list_count(commit
->parents
)) {
353 show_rev(NORMAL
, &oid
, arg
);
354 for (parents
= commit
->parents
, parent_number
= 1;
356 parents
= parents
->next
, parent_number
++) {
359 if (exclude_parent
&& parent_number
!= exclude_parent
)
363 name
= xstrfmt("%s^%d", arg
, parent_number
);
364 show_rev(include_parents
? NORMAL
: REVERSED
,
365 &parents
->item
->object
.oid
, name
);
373 static int parseopt_dump(const struct option
*o
, const char *arg
, int unset
)
375 struct strbuf
*parsed
= o
->value
;
377 strbuf_addf(parsed
, " --no-%s", o
->long_name
);
378 else if (o
->short_name
&& (o
->long_name
== NULL
|| !stuck_long
))
379 strbuf_addf(parsed
, " -%c", o
->short_name
);
381 strbuf_addf(parsed
, " --%s", o
->long_name
);
384 strbuf_addch(parsed
, ' ');
385 else if (o
->long_name
)
386 strbuf_addch(parsed
, '=');
387 sq_quote_buf(parsed
, arg
);
392 static const char *skipspaces(const char *s
)
399 static char *findspace(const char *s
)
407 static int cmd_parseopt(int argc
, const char **argv
, const char *prefix
)
409 static int keep_dashdash
= 0, stop_at_non_option
= 0;
410 static char const * const parseopt_usage
[] = {
411 N_("git rev-parse --parseopt [<options>] -- [<args>...]"),
414 static struct option parseopt_opts
[] = {
415 OPT_BOOL(0, "keep-dashdash", &keep_dashdash
,
416 N_("keep the `--` passed as an arg")),
417 OPT_BOOL(0, "stop-at-non-option", &stop_at_non_option
,
418 N_("stop parsing after the "
419 "first non-option argument")),
420 OPT_BOOL(0, "stuck-long", &stuck_long
,
421 N_("output in stuck long form")),
424 static const char * const flag_chars
= "*=?!";
426 struct strbuf sb
= STRBUF_INIT
, parsed
= STRBUF_INIT
;
427 const char **usage
= NULL
;
428 struct option
*opts
= NULL
;
429 int onb
= 0, osz
= 0, unb
= 0, usz
= 0;
431 strbuf_addstr(&parsed
, "set --");
432 argc
= parse_options(argc
, argv
, prefix
, parseopt_opts
, parseopt_usage
,
433 PARSE_OPT_KEEP_DASHDASH
);
434 if (argc
< 1 || strcmp(argv
[0], "--"))
435 usage_with_options(parseopt_usage
, parseopt_opts
);
437 /* get the usage up to the first line with a -- on it */
439 if (strbuf_getline(&sb
, stdin
) == EOF
)
440 die(_("premature end of input"));
441 ALLOC_GROW(usage
, unb
+ 1, usz
);
442 if (!strcmp("--", sb
.buf
)) {
444 die(_("no usage string given before the `--' separator"));
448 usage
[unb
++] = strbuf_detach(&sb
, NULL
);
451 /* parse: (<short>|<short>,<long>|<long>)[*=?!]*<arghint>? SP+ <help> */
452 while (strbuf_getline(&sb
, stdin
) != EOF
) {
460 ALLOC_GROW(opts
, onb
+ 1, osz
);
461 memset(opts
+ onb
, 0, sizeof(opts
[onb
]));
464 help
= findspace(sb
.buf
);
465 if (!help
|| sb
.buf
== help
) {
466 o
->type
= OPTION_GROUP
;
467 o
->help
= xstrdup(skipspaces(sb
.buf
));
473 o
->type
= OPTION_CALLBACK
;
474 o
->help
= xstrdup(skipspaces(help
+1));
476 o
->flags
= PARSE_OPT_NOARG
;
477 o
->callback
= &parseopt_dump
;
480 s
= strpbrk(sb
.buf
, flag_chars
);
485 die(_("missing opt-spec before option flags"));
487 if (s
- sb
.buf
== 1) /* short option only */
488 o
->short_name
= *sb
.buf
;
489 else if (sb
.buf
[1] != ',') /* long option only */
490 o
->long_name
= xmemdupz(sb
.buf
, s
- sb
.buf
);
492 o
->short_name
= *sb
.buf
;
493 o
->long_name
= xmemdupz(sb
.buf
+ 2, s
- sb
.buf
- 2);
500 o
->flags
&= ~PARSE_OPT_NOARG
;
503 o
->flags
&= ~PARSE_OPT_NOARG
;
504 o
->flags
|= PARSE_OPT_OPTARG
;
507 o
->flags
|= PARSE_OPT_NONEG
;
510 o
->flags
|= PARSE_OPT_HIDDEN
;
518 o
->argh
= xmemdupz(s
, help
- s
);
522 /* put an OPT_END() */
523 ALLOC_GROW(opts
, onb
+ 1, osz
);
524 memset(opts
+ onb
, 0, sizeof(opts
[onb
]));
525 argc
= parse_options(argc
, argv
, prefix
, opts
, usage
,
526 (keep_dashdash
? PARSE_OPT_KEEP_DASHDASH
: 0) |
527 (stop_at_non_option
? PARSE_OPT_STOP_AT_NON_OPTION
: 0) |
528 PARSE_OPT_SHELL_EVAL
);
530 strbuf_addstr(&parsed
, " --");
531 sq_quote_argv(&parsed
, argv
);
533 strbuf_release(&parsed
);
537 static int cmd_sq_quote(int argc
, const char **argv
)
539 struct strbuf buf
= STRBUF_INIT
;
542 sq_quote_argv(&buf
, argv
);
543 printf("%s\n", buf
.buf
);
544 strbuf_release(&buf
);
549 static void die_no_single_rev(int quiet
)
554 die(_("Needed a single revision"));
557 static const char builtin_rev_parse_usage
[] =
558 N_("git rev-parse --parseopt [<options>] -- [<args>...]\n"
559 " or: git rev-parse --sq-quote [<arg>...]\n"
560 " or: git rev-parse [<options>] [<arg>...]\n"
562 "Run \"git rev-parse --parseopt -h\" for more information on the first usage.");
565 * Parse "opt" or "opt=<value>", setting value respectively to either
566 * NULL or the string after "=".
568 static int opt_with_value(const char *arg
, const char *opt
, const char **value
)
570 if (skip_prefix(arg
, opt
, &arg
)) {
583 static void handle_ref_opt(const char *pattern
, const char *prefix
)
586 for_each_glob_ref_in(show_reference
, pattern
, prefix
, NULL
);
588 for_each_ref_in(prefix
, show_reference
, NULL
);
589 clear_ref_exclusions(&ref_excludes
);
593 /* We would like a relative path. */
595 /* We would like a canonical absolute path. */
597 /* We would like the default behavior. */
602 /* Our default is a relative path. */
604 /* Our default is a relative path if there's a shared root. */
605 DEFAULT_RELATIVE_IF_SHARED
,
606 /* Our default is a canonical absolute path. */
608 /* Our default is not to modify the item. */
612 static void print_path(const char *path
, const char *prefix
, enum format_type format
, enum default_type def
)
616 * We don't ever produce a relative path if prefix is NULL, so set the
617 * prefix to the current directory so that we can produce a relative
618 * path whenever possible. If we're using RELATIVE_IF_SHARED mode, then
619 * we want an absolute path unless the two share a common prefix, so don't
620 * set it in that case, since doing so causes a relative path to always
621 * be produced if possible.
623 if (!prefix
&& (format
!= FORMAT_DEFAULT
|| def
!= DEFAULT_RELATIVE_IF_SHARED
))
624 prefix
= cwd
= xgetcwd();
625 if (format
== FORMAT_DEFAULT
&& def
== DEFAULT_UNMODIFIED
) {
627 } else if (format
== FORMAT_RELATIVE
||
628 (format
== FORMAT_DEFAULT
&& def
== DEFAULT_RELATIVE
)) {
630 * In order for relative_path to work as expected, we need to
631 * make sure that both paths are absolute paths. If we don't,
632 * we can end up with an unexpected absolute path that the user
635 struct strbuf buf
= STRBUF_INIT
, realbuf
= STRBUF_INIT
, prefixbuf
= STRBUF_INIT
;
636 if (!is_absolute_path(path
)) {
637 strbuf_realpath_forgiving(&realbuf
, path
, 1);
640 if (!is_absolute_path(prefix
)) {
641 strbuf_realpath_forgiving(&prefixbuf
, prefix
, 1);
642 prefix
= prefixbuf
.buf
;
644 puts(relative_path(path
, prefix
, &buf
));
645 strbuf_release(&buf
);
646 strbuf_release(&realbuf
);
647 strbuf_release(&prefixbuf
);
648 } else if (format
== FORMAT_DEFAULT
&& def
== DEFAULT_RELATIVE_IF_SHARED
) {
649 struct strbuf buf
= STRBUF_INIT
;
650 puts(relative_path(path
, prefix
, &buf
));
651 strbuf_release(&buf
);
653 struct strbuf buf
= STRBUF_INIT
;
654 strbuf_realpath_forgiving(&buf
, path
, 1);
656 strbuf_release(&buf
);
661 int cmd_rev_parse(int argc
, const char **argv
, const char *prefix
)
663 int i
, as_is
= 0, verify
= 0, quiet
= 0, revs_count
= 0, type
= 0;
664 int did_repo_setup
= 0;
665 int has_dashdash
= 0;
666 int output_prefix
= 0;
667 struct object_id oid
;
668 unsigned int flags
= 0;
669 const char *name
= NULL
;
670 struct object_context unused
;
671 struct strbuf buf
= STRBUF_INIT
;
672 const int hexsz
= the_hash_algo
->hexsz
;
673 int seen_end_of_options
= 0;
674 enum format_type format
= FORMAT_DEFAULT
;
676 if (argc
> 1 && !strcmp("--parseopt", argv
[1]))
677 return cmd_parseopt(argc
- 1, argv
+ 1, prefix
);
679 if (argc
> 1 && !strcmp("--sq-quote", argv
[1]))
680 return cmd_sq_quote(argc
- 2, argv
+ 2);
682 if (argc
> 1 && !strcmp("-h", argv
[1]))
683 usage(builtin_rev_parse_usage
);
685 for (i
= 1; i
< argc
; i
++) {
686 if (!strcmp(argv
[i
], "--")) {
692 /* No options; just report on whether we're in a git repo or not. */
694 setup_git_directory();
695 git_config(git_default_config
, NULL
);
699 for (i
= 1; i
< argc
; i
++) {
700 const char *arg
= argv
[i
];
703 if (show_file(arg
, output_prefix
) && as_is
< 2)
704 verify_filename(prefix
, arg
, 0);
708 if (!seen_end_of_options
) {
709 if (!strcmp(arg
, "--local-env-vars")) {
711 for (i
= 0; local_repo_env
[i
]; i
++)
712 printf("%s\n", local_repo_env
[i
]);
715 if (!strcmp(arg
, "--resolve-git-dir")) {
716 const char *gitdir
= argv
[++i
];
718 die(_("--resolve-git-dir requires an argument"));
719 gitdir
= resolve_gitdir(gitdir
);
721 die(_("not a gitdir '%s'"), argv
[i
]);
727 /* The rest of the options require a git repository. */
728 if (!did_repo_setup
) {
729 prefix
= setup_git_directory();
730 git_config(git_default_config
, NULL
);
733 prepare_repo_settings(the_repository
);
734 the_repository
->settings
.command_requires_full_index
= 0;
737 if (!strcmp(arg
, "--")) {
739 /* Pass on the "--" if we show anything but files.. */
740 if (filter
& (DO_FLAGS
| DO_REVS
))
745 if (!seen_end_of_options
&& *arg
== '-') {
746 if (!strcmp(arg
, "--git-path")) {
748 die(_("--git-path requires an argument"));
750 print_path(git_path("%s", argv
[i
+ 1]), prefix
,
752 DEFAULT_RELATIVE_IF_SHARED
);
756 if (!strcmp(arg
,"-n")) {
758 die(_("-n requires an argument"));
759 if ((filter
& DO_FLAGS
) && (filter
& DO_REVS
)) {
765 if (starts_with(arg
, "-n")) {
766 if ((filter
& DO_FLAGS
) && (filter
& DO_REVS
))
770 if (opt_with_value(arg
, "--path-format", &arg
)) {
772 die(_("--path-format requires an argument"));
773 if (!strcmp(arg
, "absolute")) {
774 format
= FORMAT_CANONICAL
;
775 } else if (!strcmp(arg
, "relative")) {
776 format
= FORMAT_RELATIVE
;
778 die(_("unknown argument to --path-format: %s"), arg
);
782 if (!strcmp(arg
, "--default")) {
785 die(_("--default requires an argument"));
788 if (!strcmp(arg
, "--prefix")) {
791 die(_("--prefix requires an argument"));
792 startup_info
->prefix
= prefix
;
796 if (!strcmp(arg
, "--revs-only")) {
800 if (!strcmp(arg
, "--no-revs")) {
804 if (!strcmp(arg
, "--flags")) {
805 filter
&= ~DO_NONFLAGS
;
808 if (!strcmp(arg
, "--no-flags")) {
812 if (!strcmp(arg
, "--verify")) {
813 filter
&= ~(DO_FLAGS
|DO_NOREV
);
817 if (!strcmp(arg
, "--quiet") || !strcmp(arg
, "-q")) {
819 flags
|= GET_OID_QUIETLY
;
822 if (opt_with_value(arg
, "--short", &arg
)) {
823 filter
&= ~(DO_FLAGS
|DO_NOREV
);
825 abbrev
= DEFAULT_ABBREV
;
828 abbrev
= strtoul(arg
, NULL
, 10);
829 if (abbrev
< MINIMUM_ABBREV
)
830 abbrev
= MINIMUM_ABBREV
;
831 else if (hexsz
<= abbrev
)
835 if (!strcmp(arg
, "--sq")) {
839 if (!strcmp(arg
, "--not")) {
840 show_type
^= REVERSED
;
843 if (!strcmp(arg
, "--symbolic")) {
844 symbolic
= SHOW_SYMBOLIC_ASIS
;
847 if (!strcmp(arg
, "--symbolic-full-name")) {
848 symbolic
= SHOW_SYMBOLIC_FULL
;
851 if (opt_with_value(arg
, "--abbrev-ref", &arg
)) {
853 abbrev_ref_strict
= warn_ambiguous_refs
;
855 if (!strcmp(arg
, "strict"))
856 abbrev_ref_strict
= 1;
857 else if (!strcmp(arg
, "loose"))
858 abbrev_ref_strict
= 0;
860 die(_("unknown mode for --abbrev-ref: %s"),
865 if (!strcmp(arg
, "--all")) {
866 for_each_ref(show_reference
, NULL
);
867 clear_ref_exclusions(&ref_excludes
);
870 if (skip_prefix(arg
, "--disambiguate=", &arg
)) {
871 for_each_abbrev(arg
, show_abbrev
, NULL
);
874 if (!strcmp(arg
, "--bisect")) {
875 for_each_fullref_in("refs/bisect/bad", show_reference
, NULL
);
876 for_each_fullref_in("refs/bisect/good", anti_reference
, NULL
);
879 if (opt_with_value(arg
, "--branches", &arg
)) {
880 if (ref_excludes
.hidden_refs_configured
)
881 return error(_("--exclude-hidden cannot be used together with --branches"));
882 handle_ref_opt(arg
, "refs/heads/");
885 if (opt_with_value(arg
, "--tags", &arg
)) {
886 if (ref_excludes
.hidden_refs_configured
)
887 return error(_("--exclude-hidden cannot be used together with --tags"));
888 handle_ref_opt(arg
, "refs/tags/");
891 if (skip_prefix(arg
, "--glob=", &arg
)) {
892 handle_ref_opt(arg
, NULL
);
895 if (opt_with_value(arg
, "--remotes", &arg
)) {
896 if (ref_excludes
.hidden_refs_configured
)
897 return error(_("--exclude-hidden cannot be used together with --remotes"));
898 handle_ref_opt(arg
, "refs/remotes/");
901 if (skip_prefix(arg
, "--exclude=", &arg
)) {
902 add_ref_exclusion(&ref_excludes
, arg
);
905 if (skip_prefix(arg
, "--exclude-hidden=", &arg
)) {
906 exclude_hidden_refs(&ref_excludes
, arg
);
909 if (!strcmp(arg
, "--show-toplevel")) {
910 const char *work_tree
= get_git_work_tree();
912 print_path(work_tree
, prefix
, format
, DEFAULT_UNMODIFIED
);
914 die(_("this operation must be run in a work tree"));
917 if (!strcmp(arg
, "--show-superproject-working-tree")) {
918 struct strbuf superproject
= STRBUF_INIT
;
919 if (get_superproject_working_tree(&superproject
))
920 print_path(superproject
.buf
, prefix
, format
, DEFAULT_UNMODIFIED
);
921 strbuf_release(&superproject
);
924 if (!strcmp(arg
, "--show-prefix")) {
931 if (!strcmp(arg
, "--show-cdup")) {
932 const char *pfx
= prefix
;
933 if (!is_inside_work_tree()) {
934 const char *work_tree
=
937 printf("%s\n", work_tree
);
941 pfx
= strchr(pfx
, '/');
950 if (!strcmp(arg
, "--git-dir") ||
951 !strcmp(arg
, "--absolute-git-dir")) {
952 const char *gitdir
= getenv(GIT_DIR_ENVIRONMENT
);
955 enum format_type wanted
= format
;
956 if (arg
[2] == 'g') { /* --git-dir */
958 print_path(gitdir
, prefix
, format
, DEFAULT_UNMODIFIED
);
962 print_path(".git", prefix
, format
, DEFAULT_UNMODIFIED
);
965 } else { /* --absolute-git-dir */
966 wanted
= FORMAT_CANONICAL
;
967 if (!gitdir
&& !prefix
)
970 struct strbuf realpath
= STRBUF_INIT
;
971 strbuf_realpath(&realpath
, gitdir
, 1);
973 strbuf_release(&realpath
);
980 strbuf_addf(&buf
, "%s%s.git", cwd
, len
&& cwd
[len
-1] != '/' ? "/" : "");
982 print_path(buf
.buf
, prefix
, wanted
, DEFAULT_CANONICAL
);
985 if (!strcmp(arg
, "--git-common-dir")) {
986 print_path(get_git_common_dir(), prefix
, format
, DEFAULT_RELATIVE_IF_SHARED
);
989 if (!strcmp(arg
, "--is-inside-git-dir")) {
990 printf("%s\n", is_inside_git_dir() ? "true"
994 if (!strcmp(arg
, "--is-inside-work-tree")) {
995 printf("%s\n", is_inside_work_tree() ? "true"
999 if (!strcmp(arg
, "--is-bare-repository")) {
1000 printf("%s\n", is_bare_repository() ? "true"
1004 if (!strcmp(arg
, "--is-shallow-repository")) {
1006 is_repository_shallow(the_repository
) ? "true"
1010 if (!strcmp(arg
, "--shared-index-path")) {
1011 if (repo_read_index(the_repository
) < 0)
1012 die(_("Could not read the index"));
1013 if (the_index
.split_index
) {
1014 const struct object_id
*oid
= &the_index
.split_index
->base_oid
;
1015 const char *path
= git_path("sharedindex.%s", oid_to_hex(oid
));
1016 print_path(path
, prefix
, format
, DEFAULT_RELATIVE
);
1020 if (skip_prefix(arg
, "--since=", &arg
)) {
1021 show_datestring("--max-age=", arg
);
1024 if (skip_prefix(arg
, "--after=", &arg
)) {
1025 show_datestring("--max-age=", arg
);
1028 if (skip_prefix(arg
, "--before=", &arg
)) {
1029 show_datestring("--min-age=", arg
);
1032 if (skip_prefix(arg
, "--until=", &arg
)) {
1033 show_datestring("--min-age=", arg
);
1036 if (opt_with_value(arg
, "--show-object-format", &arg
)) {
1037 const char *val
= arg
? arg
: "storage";
1039 if (strcmp(val
, "storage") &&
1040 strcmp(val
, "input") &&
1041 strcmp(val
, "output"))
1042 die(_("unknown mode for --show-object-format: %s"),
1044 puts(the_hash_algo
->name
);
1047 if (!strcmp(arg
, "--end-of-options")) {
1048 seen_end_of_options
= 1;
1049 if (filter
& (DO_FLAGS
| DO_REVS
))
1053 if (show_flag(arg
) && verify
)
1054 die_no_single_rev(quiet
);
1058 /* Not a flag argument */
1059 if (try_difference(arg
))
1061 if (try_parent_shorthands(arg
))
1069 if (!get_oid_with_context(the_repository
, name
,
1070 flags
, &oid
, &unused
)) {
1074 show_rev(type
, &oid
, name
);
1078 die_no_single_rev(quiet
);
1080 die(_("bad revision '%s'"), arg
);
1082 if (!show_file(arg
, output_prefix
))
1084 verify_filename(prefix
, arg
, 1);
1086 strbuf_release(&buf
);
1088 if (revs_count
== 1) {
1089 show_rev(type
, &oid
, name
);
1091 } else if (revs_count
== 0 && show_default())
1093 die_no_single_rev(quiet
);