4 * Copyright (C) Linus Torvalds, 2005
6 #define USE_THE_INDEX_VARIABLE
14 #include "parse-options.h"
17 #include "split-index.h"
18 #include "submodule.h"
19 #include "commit-reach.h"
26 static int filter
= ~0;
28 static const char *def
;
32 static int show_type
= NORMAL
;
34 #define SHOW_SYMBOLIC_ASIS 1
35 #define SHOW_SYMBOLIC_FULL 2
38 static int abbrev_ref
;
39 static int abbrev_ref_strict
;
42 static int stuck_long
;
43 static struct ref_exclusions ref_excludes
= REF_EXCLUSIONS_INIT
;
46 * Some arguments are relevant "revision" arguments,
47 * others are about output format or other details.
48 * This sorts it all out.
50 static int is_rev_argument(const char *arg
)
52 static const char *rev_args
[] = {
83 const char **p
= rev_args
;
85 /* accept -<digit>, like traditional "head" */
86 if ((*arg
== '-') && isdigit(arg
[1]))
90 const char *str
= *p
++;
95 if (!strcmp(arg
, str
) ||
96 (str
[len
-1] == '=' && !strncmp(arg
, str
, len
)))
101 /* Output argument as a string, either SQ or normal */
102 static void show(const char *arg
)
108 while ((ch
= *arg
++)) {
110 fputs("'\\'", stdout
);
120 /* Like show(), but with a negation prefix according to type */
121 static void show_with_type(int type
, const char *arg
)
123 if (type
!= show_type
)
128 /* Output a revision, only if filter allows it */
129 static void show_rev(int type
, const struct object_id
*oid
, const char *name
)
131 if (!(filter
& DO_REVS
))
135 if ((symbolic
|| abbrev_ref
) && name
) {
136 if (symbolic
== SHOW_SYMBOLIC_FULL
|| abbrev_ref
) {
137 struct object_id discard
;
140 switch (dwim_ref(name
, strlen(name
), &discard
, &full
, 0)) {
143 * Not found -- not a ref. We could
144 * emit "name" here, but symbolic-full
145 * users are interested in finding the
146 * refs spelled in full, and they would
147 * need to filter non-refs if we did so.
152 full
= shorten_unambiguous_ref(full
,
154 show_with_type(type
, full
);
156 default: /* ambiguous */
157 error("refname '%s' is ambiguous", name
);
162 show_with_type(type
, name
);
166 show_with_type(type
, find_unique_abbrev(oid
, abbrev
));
168 show_with_type(type
, oid_to_hex(oid
));
171 /* Output a flag, only if filter allows it. */
172 static int show_flag(const char *arg
)
174 if (!(filter
& DO_FLAGS
))
176 if (filter
& (is_rev_argument(arg
) ? DO_REVS
: DO_NOREV
)) {
183 static int show_default(void)
188 struct object_id oid
;
191 if (!get_oid(s
, &oid
)) {
192 show_rev(NORMAL
, &oid
, s
);
199 static int show_reference(const char *refname
, const struct object_id
*oid
,
200 int flag UNUSED
, void *cb_data UNUSED
)
202 if (ref_excluded(&ref_excludes
, refname
))
204 show_rev(NORMAL
, oid
, refname
);
208 static int anti_reference(const char *refname
, const struct object_id
*oid
,
209 int flag UNUSED
, void *cb_data UNUSED
)
211 show_rev(REVERSED
, oid
, refname
);
215 static int show_abbrev(const struct object_id
*oid
, void *cb_data
)
217 show_rev(NORMAL
, oid
, NULL
);
221 static void show_datestring(const char *flag
, const char *datestr
)
225 /* date handling requires both flags and revs */
226 if ((filter
& (DO_FLAGS
| DO_REVS
)) != (DO_FLAGS
| DO_REVS
))
228 buffer
= xstrfmt("%s%"PRItime
, flag
, approxidate(datestr
));
233 static int show_file(const char *arg
, int output_prefix
)
236 if ((filter
& (DO_NONFLAGS
|DO_NOREV
)) == (DO_NONFLAGS
|DO_NOREV
)) {
238 const char *prefix
= startup_info
->prefix
;
239 char *fname
= prefix_filename(prefix
, arg
);
249 static int try_difference(const char *arg
)
252 struct object_id start_oid
;
253 struct object_id end_oid
;
257 static const char head_by_default
[] = "HEAD";
259 if (!(dotdot
= strstr(arg
, "..")))
263 symmetric
= (*end
== '.');
269 end
= head_by_default
;
271 start
= head_by_default
;
273 if (start
== head_by_default
&& end
== head_by_default
&&
276 * Just ".."? That is not a range but the
277 * pathspec for the parent directory.
283 if (!get_oid_committish(start
, &start_oid
) && !get_oid_committish(end
, &end_oid
)) {
284 show_rev(NORMAL
, &end_oid
, end
);
285 show_rev(symmetric
? NORMAL
: REVERSED
, &start_oid
, start
);
287 struct commit_list
*exclude
;
288 struct commit
*a
, *b
;
289 a
= lookup_commit_reference(the_repository
, &start_oid
);
290 b
= lookup_commit_reference(the_repository
, &end_oid
);
295 exclude
= get_merge_bases(a
, b
);
297 struct commit
*commit
= pop_commit(&exclude
);
298 show_rev(REVERSED
, &commit
->object
.oid
, NULL
);
308 static int try_parent_shorthands(const char *arg
)
311 struct object_id oid
;
312 struct commit
*commit
;
313 struct commit_list
*parents
;
316 int include_parents
= 0;
317 int exclude_parent
= 0;
319 if ((dotdot
= strstr(arg
, "^!"))) {
323 } else if ((dotdot
= strstr(arg
, "^@"))) {
327 } else if ((dotdot
= strstr(arg
, "^-"))) {
333 exclude_parent
= strtoul(dotdot
+ 2, &end
, 10);
334 if (*end
!= '\0' || !exclude_parent
)
341 if (get_oid_committish(arg
, &oid
) ||
342 !(commit
= lookup_commit_reference(the_repository
, &oid
))) {
347 if (exclude_parent
&&
348 exclude_parent
> commit_list_count(commit
->parents
)) {
354 show_rev(NORMAL
, &oid
, arg
);
355 for (parents
= commit
->parents
, parent_number
= 1;
357 parents
= parents
->next
, parent_number
++) {
360 if (exclude_parent
&& parent_number
!= exclude_parent
)
364 name
= xstrfmt("%s^%d", arg
, parent_number
);
365 show_rev(include_parents
? NORMAL
: REVERSED
,
366 &parents
->item
->object
.oid
, name
);
374 static int parseopt_dump(const struct option
*o
, const char *arg
, int unset
)
376 struct strbuf
*parsed
= o
->value
;
378 strbuf_addf(parsed
, " --no-%s", o
->long_name
);
379 else if (o
->short_name
&& (o
->long_name
== NULL
|| !stuck_long
))
380 strbuf_addf(parsed
, " -%c", o
->short_name
);
382 strbuf_addf(parsed
, " --%s", o
->long_name
);
385 strbuf_addch(parsed
, ' ');
386 else if (o
->long_name
)
387 strbuf_addch(parsed
, '=');
388 sq_quote_buf(parsed
, arg
);
393 static const char *skipspaces(const char *s
)
400 static char *findspace(const char *s
)
408 static int cmd_parseopt(int argc
, const char **argv
, const char *prefix
)
410 static int keep_dashdash
= 0, stop_at_non_option
= 0;
411 static char const * const parseopt_usage
[] = {
412 N_("git rev-parse --parseopt [<options>] -- [<args>...]"),
415 static struct option parseopt_opts
[] = {
416 OPT_BOOL(0, "keep-dashdash", &keep_dashdash
,
417 N_("keep the `--` passed as an arg")),
418 OPT_BOOL(0, "stop-at-non-option", &stop_at_non_option
,
419 N_("stop parsing after the "
420 "first non-option argument")),
421 OPT_BOOL(0, "stuck-long", &stuck_long
,
422 N_("output in stuck long form")),
425 static const char * const flag_chars
= "*=?!";
427 struct strbuf sb
= STRBUF_INIT
, parsed
= STRBUF_INIT
;
428 const char **usage
= NULL
;
429 struct option
*opts
= NULL
;
430 int onb
= 0, osz
= 0, unb
= 0, usz
= 0;
432 strbuf_addstr(&parsed
, "set --");
433 argc
= parse_options(argc
, argv
, prefix
, parseopt_opts
, parseopt_usage
,
434 PARSE_OPT_KEEP_DASHDASH
);
435 if (argc
< 1 || strcmp(argv
[0], "--"))
436 usage_with_options(parseopt_usage
, parseopt_opts
);
438 /* get the usage up to the first line with a -- on it */
440 if (strbuf_getline(&sb
, stdin
) == EOF
)
441 die(_("premature end of input"));
442 ALLOC_GROW(usage
, unb
+ 1, usz
);
443 if (!strcmp("--", sb
.buf
)) {
445 die(_("no usage string given before the `--' separator"));
449 usage
[unb
++] = strbuf_detach(&sb
, NULL
);
452 /* parse: (<short>|<short>,<long>|<long>)[*=?!]*<arghint>? SP+ <help> */
453 while (strbuf_getline(&sb
, stdin
) != EOF
) {
461 ALLOC_GROW(opts
, onb
+ 1, osz
);
462 memset(opts
+ onb
, 0, sizeof(opts
[onb
]));
465 help
= findspace(sb
.buf
);
466 if (!help
|| sb
.buf
== help
) {
467 o
->type
= OPTION_GROUP
;
468 o
->help
= xstrdup(skipspaces(sb
.buf
));
474 o
->type
= OPTION_CALLBACK
;
475 o
->help
= xstrdup(skipspaces(help
+1));
477 o
->flags
= PARSE_OPT_NOARG
;
478 o
->callback
= &parseopt_dump
;
481 s
= strpbrk(sb
.buf
, flag_chars
);
486 die(_("missing opt-spec before option flags"));
488 if (s
- sb
.buf
== 1) /* short option only */
489 o
->short_name
= *sb
.buf
;
490 else if (sb
.buf
[1] != ',') /* long option only */
491 o
->long_name
= xmemdupz(sb
.buf
, s
- sb
.buf
);
493 o
->short_name
= *sb
.buf
;
494 o
->long_name
= xmemdupz(sb
.buf
+ 2, s
- sb
.buf
- 2);
501 o
->flags
&= ~PARSE_OPT_NOARG
;
504 o
->flags
&= ~PARSE_OPT_NOARG
;
505 o
->flags
|= PARSE_OPT_OPTARG
;
508 o
->flags
|= PARSE_OPT_NONEG
;
511 o
->flags
|= PARSE_OPT_HIDDEN
;
519 o
->argh
= xmemdupz(s
, help
- s
);
523 /* put an OPT_END() */
524 ALLOC_GROW(opts
, onb
+ 1, osz
);
525 memset(opts
+ onb
, 0, sizeof(opts
[onb
]));
526 argc
= parse_options(argc
, argv
, prefix
, opts
, usage
,
527 (keep_dashdash
? PARSE_OPT_KEEP_DASHDASH
: 0) |
528 (stop_at_non_option
? PARSE_OPT_STOP_AT_NON_OPTION
: 0) |
529 PARSE_OPT_SHELL_EVAL
);
531 strbuf_addstr(&parsed
, " --");
532 sq_quote_argv(&parsed
, argv
);
534 strbuf_release(&parsed
);
538 static int cmd_sq_quote(int argc
, const char **argv
)
540 struct strbuf buf
= STRBUF_INIT
;
543 sq_quote_argv(&buf
, argv
);
544 printf("%s\n", buf
.buf
);
545 strbuf_release(&buf
);
550 static void die_no_single_rev(int quiet
)
555 die(_("Needed a single revision"));
558 static const char builtin_rev_parse_usage
[] =
559 N_("git rev-parse --parseopt [<options>] -- [<args>...]\n"
560 " or: git rev-parse --sq-quote [<arg>...]\n"
561 " or: git rev-parse [<options>] [<arg>...]\n"
563 "Run \"git rev-parse --parseopt -h\" for more information on the first usage.");
566 * Parse "opt" or "opt=<value>", setting value respectively to either
567 * NULL or the string after "=".
569 static int opt_with_value(const char *arg
, const char *opt
, const char **value
)
571 if (skip_prefix(arg
, opt
, &arg
)) {
584 static void handle_ref_opt(const char *pattern
, const char *prefix
)
587 for_each_glob_ref_in(show_reference
, pattern
, prefix
, NULL
);
589 for_each_ref_in(prefix
, show_reference
, NULL
);
590 clear_ref_exclusions(&ref_excludes
);
594 /* We would like a relative path. */
596 /* We would like a canonical absolute path. */
598 /* We would like the default behavior. */
603 /* Our default is a relative path. */
605 /* Our default is a relative path if there's a shared root. */
606 DEFAULT_RELATIVE_IF_SHARED
,
607 /* Our default is a canonical absolute path. */
609 /* Our default is not to modify the item. */
613 static void print_path(const char *path
, const char *prefix
, enum format_type format
, enum default_type def
)
617 * We don't ever produce a relative path if prefix is NULL, so set the
618 * prefix to the current directory so that we can produce a relative
619 * path whenever possible. If we're using RELATIVE_IF_SHARED mode, then
620 * we want an absolute path unless the two share a common prefix, so don't
621 * set it in that case, since doing so causes a relative path to always
622 * be produced if possible.
624 if (!prefix
&& (format
!= FORMAT_DEFAULT
|| def
!= DEFAULT_RELATIVE_IF_SHARED
))
625 prefix
= cwd
= xgetcwd();
626 if (format
== FORMAT_DEFAULT
&& def
== DEFAULT_UNMODIFIED
) {
628 } else if (format
== FORMAT_RELATIVE
||
629 (format
== FORMAT_DEFAULT
&& def
== DEFAULT_RELATIVE
)) {
631 * In order for relative_path to work as expected, we need to
632 * make sure that both paths are absolute paths. If we don't,
633 * we can end up with an unexpected absolute path that the user
636 struct strbuf buf
= STRBUF_INIT
, realbuf
= STRBUF_INIT
, prefixbuf
= STRBUF_INIT
;
637 if (!is_absolute_path(path
)) {
638 strbuf_realpath_forgiving(&realbuf
, path
, 1);
641 if (!is_absolute_path(prefix
)) {
642 strbuf_realpath_forgiving(&prefixbuf
, prefix
, 1);
643 prefix
= prefixbuf
.buf
;
645 puts(relative_path(path
, prefix
, &buf
));
646 strbuf_release(&buf
);
647 strbuf_release(&realbuf
);
648 strbuf_release(&prefixbuf
);
649 } else if (format
== FORMAT_DEFAULT
&& def
== DEFAULT_RELATIVE_IF_SHARED
) {
650 struct strbuf buf
= STRBUF_INIT
;
651 puts(relative_path(path
, prefix
, &buf
));
652 strbuf_release(&buf
);
654 struct strbuf buf
= STRBUF_INIT
;
655 strbuf_realpath_forgiving(&buf
, path
, 1);
657 strbuf_release(&buf
);
662 int cmd_rev_parse(int argc
, const char **argv
, const char *prefix
)
664 int i
, as_is
= 0, verify
= 0, quiet
= 0, revs_count
= 0, type
= 0;
665 int did_repo_setup
= 0;
666 int has_dashdash
= 0;
667 int output_prefix
= 0;
668 struct object_id oid
;
669 unsigned int flags
= 0;
670 const char *name
= NULL
;
671 struct object_context unused
;
672 struct strbuf buf
= STRBUF_INIT
;
673 const int hexsz
= the_hash_algo
->hexsz
;
674 int seen_end_of_options
= 0;
675 enum format_type format
= FORMAT_DEFAULT
;
677 if (argc
> 1 && !strcmp("--parseopt", argv
[1]))
678 return cmd_parseopt(argc
- 1, argv
+ 1, prefix
);
680 if (argc
> 1 && !strcmp("--sq-quote", argv
[1]))
681 return cmd_sq_quote(argc
- 2, argv
+ 2);
683 if (argc
> 1 && !strcmp("-h", argv
[1]))
684 usage(builtin_rev_parse_usage
);
686 for (i
= 1; i
< argc
; i
++) {
687 if (!strcmp(argv
[i
], "--")) {
693 /* No options; just report on whether we're in a git repo or not. */
695 setup_git_directory();
696 git_config(git_default_config
, NULL
);
700 for (i
= 1; i
< argc
; i
++) {
701 const char *arg
= argv
[i
];
704 if (show_file(arg
, output_prefix
) && as_is
< 2)
705 verify_filename(prefix
, arg
, 0);
709 if (!seen_end_of_options
) {
710 if (!strcmp(arg
, "--local-env-vars")) {
712 for (i
= 0; local_repo_env
[i
]; i
++)
713 printf("%s\n", local_repo_env
[i
]);
716 if (!strcmp(arg
, "--resolve-git-dir")) {
717 const char *gitdir
= argv
[++i
];
719 die(_("--resolve-git-dir requires an argument"));
720 gitdir
= resolve_gitdir(gitdir
);
722 die(_("not a gitdir '%s'"), argv
[i
]);
728 /* The rest of the options require a git repository. */
729 if (!did_repo_setup
) {
730 prefix
= setup_git_directory();
731 git_config(git_default_config
, NULL
);
734 prepare_repo_settings(the_repository
);
735 the_repository
->settings
.command_requires_full_index
= 0;
738 if (!strcmp(arg
, "--")) {
740 /* Pass on the "--" if we show anything but files.. */
741 if (filter
& (DO_FLAGS
| DO_REVS
))
746 if (!seen_end_of_options
&& *arg
== '-') {
747 if (!strcmp(arg
, "--git-path")) {
749 die(_("--git-path requires an argument"));
751 print_path(git_path("%s", argv
[i
+ 1]), prefix
,
753 DEFAULT_RELATIVE_IF_SHARED
);
757 if (!strcmp(arg
,"-n")) {
759 die(_("-n requires an argument"));
760 if ((filter
& DO_FLAGS
) && (filter
& DO_REVS
)) {
766 if (starts_with(arg
, "-n")) {
767 if ((filter
& DO_FLAGS
) && (filter
& DO_REVS
))
771 if (opt_with_value(arg
, "--path-format", &arg
)) {
773 die(_("--path-format requires an argument"));
774 if (!strcmp(arg
, "absolute")) {
775 format
= FORMAT_CANONICAL
;
776 } else if (!strcmp(arg
, "relative")) {
777 format
= FORMAT_RELATIVE
;
779 die(_("unknown argument to --path-format: %s"), arg
);
783 if (!strcmp(arg
, "--default")) {
786 die(_("--default requires an argument"));
789 if (!strcmp(arg
, "--prefix")) {
792 die(_("--prefix requires an argument"));
793 startup_info
->prefix
= prefix
;
797 if (!strcmp(arg
, "--revs-only")) {
801 if (!strcmp(arg
, "--no-revs")) {
805 if (!strcmp(arg
, "--flags")) {
806 filter
&= ~DO_NONFLAGS
;
809 if (!strcmp(arg
, "--no-flags")) {
813 if (!strcmp(arg
, "--verify")) {
814 filter
&= ~(DO_FLAGS
|DO_NOREV
);
818 if (!strcmp(arg
, "--quiet") || !strcmp(arg
, "-q")) {
820 flags
|= GET_OID_QUIETLY
;
823 if (opt_with_value(arg
, "--short", &arg
)) {
824 filter
&= ~(DO_FLAGS
|DO_NOREV
);
826 abbrev
= DEFAULT_ABBREV
;
829 abbrev
= strtoul(arg
, NULL
, 10);
830 if (abbrev
< MINIMUM_ABBREV
)
831 abbrev
= MINIMUM_ABBREV
;
832 else if (hexsz
<= abbrev
)
836 if (!strcmp(arg
, "--sq")) {
840 if (!strcmp(arg
, "--not")) {
841 show_type
^= REVERSED
;
844 if (!strcmp(arg
, "--symbolic")) {
845 symbolic
= SHOW_SYMBOLIC_ASIS
;
848 if (!strcmp(arg
, "--symbolic-full-name")) {
849 symbolic
= SHOW_SYMBOLIC_FULL
;
852 if (opt_with_value(arg
, "--abbrev-ref", &arg
)) {
854 abbrev_ref_strict
= warn_ambiguous_refs
;
856 if (!strcmp(arg
, "strict"))
857 abbrev_ref_strict
= 1;
858 else if (!strcmp(arg
, "loose"))
859 abbrev_ref_strict
= 0;
861 die(_("unknown mode for --abbrev-ref: %s"),
866 if (!strcmp(arg
, "--all")) {
867 for_each_ref(show_reference
, NULL
);
868 clear_ref_exclusions(&ref_excludes
);
871 if (skip_prefix(arg
, "--disambiguate=", &arg
)) {
872 for_each_abbrev(arg
, show_abbrev
, NULL
);
875 if (!strcmp(arg
, "--bisect")) {
876 for_each_fullref_in("refs/bisect/bad", show_reference
, NULL
);
877 for_each_fullref_in("refs/bisect/good", anti_reference
, NULL
);
880 if (opt_with_value(arg
, "--branches", &arg
)) {
881 if (ref_excludes
.hidden_refs_configured
)
882 return error(_("--exclude-hidden cannot be used together with --branches"));
883 handle_ref_opt(arg
, "refs/heads/");
886 if (opt_with_value(arg
, "--tags", &arg
)) {
887 if (ref_excludes
.hidden_refs_configured
)
888 return error(_("--exclude-hidden cannot be used together with --tags"));
889 handle_ref_opt(arg
, "refs/tags/");
892 if (skip_prefix(arg
, "--glob=", &arg
)) {
893 handle_ref_opt(arg
, NULL
);
896 if (opt_with_value(arg
, "--remotes", &arg
)) {
897 if (ref_excludes
.hidden_refs_configured
)
898 return error(_("--exclude-hidden cannot be used together with --remotes"));
899 handle_ref_opt(arg
, "refs/remotes/");
902 if (skip_prefix(arg
, "--exclude=", &arg
)) {
903 add_ref_exclusion(&ref_excludes
, arg
);
906 if (skip_prefix(arg
, "--exclude-hidden=", &arg
)) {
907 exclude_hidden_refs(&ref_excludes
, arg
);
910 if (!strcmp(arg
, "--show-toplevel")) {
911 const char *work_tree
= get_git_work_tree();
913 print_path(work_tree
, prefix
, format
, DEFAULT_UNMODIFIED
);
915 die(_("this operation must be run in a work tree"));
918 if (!strcmp(arg
, "--show-superproject-working-tree")) {
919 struct strbuf superproject
= STRBUF_INIT
;
920 if (get_superproject_working_tree(&superproject
))
921 print_path(superproject
.buf
, prefix
, format
, DEFAULT_UNMODIFIED
);
922 strbuf_release(&superproject
);
925 if (!strcmp(arg
, "--show-prefix")) {
932 if (!strcmp(arg
, "--show-cdup")) {
933 const char *pfx
= prefix
;
934 if (!is_inside_work_tree()) {
935 const char *work_tree
=
938 printf("%s\n", work_tree
);
942 pfx
= strchr(pfx
, '/');
951 if (!strcmp(arg
, "--git-dir") ||
952 !strcmp(arg
, "--absolute-git-dir")) {
953 const char *gitdir
= getenv(GIT_DIR_ENVIRONMENT
);
956 enum format_type wanted
= format
;
957 if (arg
[2] == 'g') { /* --git-dir */
959 print_path(gitdir
, prefix
, format
, DEFAULT_UNMODIFIED
);
963 print_path(".git", prefix
, format
, DEFAULT_UNMODIFIED
);
966 } else { /* --absolute-git-dir */
967 wanted
= FORMAT_CANONICAL
;
968 if (!gitdir
&& !prefix
)
971 struct strbuf realpath
= STRBUF_INIT
;
972 strbuf_realpath(&realpath
, gitdir
, 1);
974 strbuf_release(&realpath
);
981 strbuf_addf(&buf
, "%s%s.git", cwd
, len
&& cwd
[len
-1] != '/' ? "/" : "");
983 print_path(buf
.buf
, prefix
, wanted
, DEFAULT_CANONICAL
);
986 if (!strcmp(arg
, "--git-common-dir")) {
987 print_path(get_git_common_dir(), prefix
, format
, DEFAULT_RELATIVE_IF_SHARED
);
990 if (!strcmp(arg
, "--is-inside-git-dir")) {
991 printf("%s\n", is_inside_git_dir() ? "true"
995 if (!strcmp(arg
, "--is-inside-work-tree")) {
996 printf("%s\n", is_inside_work_tree() ? "true"
1000 if (!strcmp(arg
, "--is-bare-repository")) {
1001 printf("%s\n", is_bare_repository() ? "true"
1005 if (!strcmp(arg
, "--is-shallow-repository")) {
1007 is_repository_shallow(the_repository
) ? "true"
1011 if (!strcmp(arg
, "--shared-index-path")) {
1012 if (repo_read_index(the_repository
) < 0)
1013 die(_("Could not read the index"));
1014 if (the_index
.split_index
) {
1015 const struct object_id
*oid
= &the_index
.split_index
->base_oid
;
1016 const char *path
= git_path("sharedindex.%s", oid_to_hex(oid
));
1017 print_path(path
, prefix
, format
, DEFAULT_RELATIVE
);
1021 if (skip_prefix(arg
, "--since=", &arg
)) {
1022 show_datestring("--max-age=", arg
);
1025 if (skip_prefix(arg
, "--after=", &arg
)) {
1026 show_datestring("--max-age=", arg
);
1029 if (skip_prefix(arg
, "--before=", &arg
)) {
1030 show_datestring("--min-age=", arg
);
1033 if (skip_prefix(arg
, "--until=", &arg
)) {
1034 show_datestring("--min-age=", arg
);
1037 if (opt_with_value(arg
, "--show-object-format", &arg
)) {
1038 const char *val
= arg
? arg
: "storage";
1040 if (strcmp(val
, "storage") &&
1041 strcmp(val
, "input") &&
1042 strcmp(val
, "output"))
1043 die(_("unknown mode for --show-object-format: %s"),
1045 puts(the_hash_algo
->name
);
1048 if (!strcmp(arg
, "--end-of-options")) {
1049 seen_end_of_options
= 1;
1050 if (filter
& (DO_FLAGS
| DO_REVS
))
1054 if (show_flag(arg
) && verify
)
1055 die_no_single_rev(quiet
);
1059 /* Not a flag argument */
1060 if (try_difference(arg
))
1062 if (try_parent_shorthands(arg
))
1070 if (!get_oid_with_context(the_repository
, name
,
1071 flags
, &oid
, &unused
)) {
1075 show_rev(type
, &oid
, name
);
1079 die_no_single_rev(quiet
);
1081 die(_("bad revision '%s'"), arg
);
1083 if (!show_file(arg
, output_prefix
))
1085 verify_filename(prefix
, arg
, 1);
1087 strbuf_release(&buf
);
1089 if (revs_count
== 1) {
1090 show_rev(type
, &oid
, name
);
1092 } else if (revs_count
== 0 && show_default())
1094 die_no_single_rev(quiet
);