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
);
536 static int cmd_sq_quote(int argc
, const char **argv
)
538 struct strbuf buf
= STRBUF_INIT
;
541 sq_quote_argv(&buf
, argv
);
542 printf("%s\n", buf
.buf
);
543 strbuf_release(&buf
);
548 static void die_no_single_rev(int quiet
)
553 die(_("Needed a single revision"));
556 static const char builtin_rev_parse_usage
[] =
557 N_("git rev-parse --parseopt [<options>] -- [<args>...]\n"
558 " or: git rev-parse --sq-quote [<arg>...]\n"
559 " or: git rev-parse [<options>] [<arg>...]\n"
561 "Run \"git rev-parse --parseopt -h\" for more information on the first usage.");
564 * Parse "opt" or "opt=<value>", setting value respectively to either
565 * NULL or the string after "=".
567 static int opt_with_value(const char *arg
, const char *opt
, const char **value
)
569 if (skip_prefix(arg
, opt
, &arg
)) {
582 static void handle_ref_opt(const char *pattern
, const char *prefix
)
585 for_each_glob_ref_in(show_reference
, pattern
, prefix
, NULL
);
587 for_each_ref_in(prefix
, show_reference
, NULL
);
588 clear_ref_exclusions(&ref_excludes
);
592 /* We would like a relative path. */
594 /* We would like a canonical absolute path. */
596 /* We would like the default behavior. */
601 /* Our default is a relative path. */
603 /* Our default is a relative path if there's a shared root. */
604 DEFAULT_RELATIVE_IF_SHARED
,
605 /* Our default is a canonical absolute path. */
607 /* Our default is not to modify the item. */
611 static void print_path(const char *path
, const char *prefix
, enum format_type format
, enum default_type def
)
615 * We don't ever produce a relative path if prefix is NULL, so set the
616 * prefix to the current directory so that we can produce a relative
617 * path whenever possible. If we're using RELATIVE_IF_SHARED mode, then
618 * we want an absolute path unless the two share a common prefix, so don't
619 * set it in that case, since doing so causes a relative path to always
620 * be produced if possible.
622 if (!prefix
&& (format
!= FORMAT_DEFAULT
|| def
!= DEFAULT_RELATIVE_IF_SHARED
))
623 prefix
= cwd
= xgetcwd();
624 if (format
== FORMAT_DEFAULT
&& def
== DEFAULT_UNMODIFIED
) {
626 } else if (format
== FORMAT_RELATIVE
||
627 (format
== FORMAT_DEFAULT
&& def
== DEFAULT_RELATIVE
)) {
629 * In order for relative_path to work as expected, we need to
630 * make sure that both paths are absolute paths. If we don't,
631 * we can end up with an unexpected absolute path that the user
634 struct strbuf buf
= STRBUF_INIT
, realbuf
= STRBUF_INIT
, prefixbuf
= STRBUF_INIT
;
635 if (!is_absolute_path(path
)) {
636 strbuf_realpath_forgiving(&realbuf
, path
, 1);
639 if (!is_absolute_path(prefix
)) {
640 strbuf_realpath_forgiving(&prefixbuf
, prefix
, 1);
641 prefix
= prefixbuf
.buf
;
643 puts(relative_path(path
, prefix
, &buf
));
644 strbuf_release(&buf
);
645 strbuf_release(&realbuf
);
646 strbuf_release(&prefixbuf
);
647 } else if (format
== FORMAT_DEFAULT
&& def
== DEFAULT_RELATIVE_IF_SHARED
) {
648 struct strbuf buf
= STRBUF_INIT
;
649 puts(relative_path(path
, prefix
, &buf
));
650 strbuf_release(&buf
);
652 struct strbuf buf
= STRBUF_INIT
;
653 strbuf_realpath_forgiving(&buf
, path
, 1);
655 strbuf_release(&buf
);
660 int cmd_rev_parse(int argc
, const char **argv
, const char *prefix
)
662 int i
, as_is
= 0, verify
= 0, quiet
= 0, revs_count
= 0, type
= 0;
663 int did_repo_setup
= 0;
664 int has_dashdash
= 0;
665 int output_prefix
= 0;
666 struct object_id oid
;
667 unsigned int flags
= 0;
668 const char *name
= NULL
;
669 struct object_context unused
;
670 struct strbuf buf
= STRBUF_INIT
;
671 const int hexsz
= the_hash_algo
->hexsz
;
672 int seen_end_of_options
= 0;
673 enum format_type format
= FORMAT_DEFAULT
;
675 if (argc
> 1 && !strcmp("--parseopt", argv
[1]))
676 return cmd_parseopt(argc
- 1, argv
+ 1, prefix
);
678 if (argc
> 1 && !strcmp("--sq-quote", argv
[1]))
679 return cmd_sq_quote(argc
- 2, argv
+ 2);
681 if (argc
> 1 && !strcmp("-h", argv
[1]))
682 usage(builtin_rev_parse_usage
);
684 for (i
= 1; i
< argc
; i
++) {
685 if (!strcmp(argv
[i
], "--")) {
691 /* No options; just report on whether we're in a git repo or not. */
693 setup_git_directory();
694 git_config(git_default_config
, NULL
);
698 for (i
= 1; i
< argc
; i
++) {
699 const char *arg
= argv
[i
];
702 if (show_file(arg
, output_prefix
) && as_is
< 2)
703 verify_filename(prefix
, arg
, 0);
707 if (!seen_end_of_options
) {
708 if (!strcmp(arg
, "--local-env-vars")) {
710 for (i
= 0; local_repo_env
[i
]; i
++)
711 printf("%s\n", local_repo_env
[i
]);
714 if (!strcmp(arg
, "--resolve-git-dir")) {
715 const char *gitdir
= argv
[++i
];
717 die(_("--resolve-git-dir requires an argument"));
718 gitdir
= resolve_gitdir(gitdir
);
720 die(_("not a gitdir '%s'"), argv
[i
]);
726 /* The rest of the options require a git repository. */
727 if (!did_repo_setup
) {
728 prefix
= setup_git_directory();
729 git_config(git_default_config
, NULL
);
732 prepare_repo_settings(the_repository
);
733 the_repository
->settings
.command_requires_full_index
= 0;
736 if (!strcmp(arg
, "--")) {
738 /* Pass on the "--" if we show anything but files.. */
739 if (filter
& (DO_FLAGS
| DO_REVS
))
744 if (!seen_end_of_options
&& *arg
== '-') {
745 if (!strcmp(arg
, "--git-path")) {
747 die(_("--git-path requires an argument"));
749 print_path(git_path("%s", argv
[i
+ 1]), prefix
,
751 DEFAULT_RELATIVE_IF_SHARED
);
755 if (!strcmp(arg
,"-n")) {
757 die(_("-n requires an argument"));
758 if ((filter
& DO_FLAGS
) && (filter
& DO_REVS
)) {
764 if (starts_with(arg
, "-n")) {
765 if ((filter
& DO_FLAGS
) && (filter
& DO_REVS
))
769 if (opt_with_value(arg
, "--path-format", &arg
)) {
771 die(_("--path-format requires an argument"));
772 if (!strcmp(arg
, "absolute")) {
773 format
= FORMAT_CANONICAL
;
774 } else if (!strcmp(arg
, "relative")) {
775 format
= FORMAT_RELATIVE
;
777 die(_("unknown argument to --path-format: %s"), arg
);
781 if (!strcmp(arg
, "--default")) {
784 die(_("--default requires an argument"));
787 if (!strcmp(arg
, "--prefix")) {
790 die(_("--prefix requires an argument"));
791 startup_info
->prefix
= prefix
;
795 if (!strcmp(arg
, "--revs-only")) {
799 if (!strcmp(arg
, "--no-revs")) {
803 if (!strcmp(arg
, "--flags")) {
804 filter
&= ~DO_NONFLAGS
;
807 if (!strcmp(arg
, "--no-flags")) {
811 if (!strcmp(arg
, "--verify")) {
812 filter
&= ~(DO_FLAGS
|DO_NOREV
);
816 if (!strcmp(arg
, "--quiet") || !strcmp(arg
, "-q")) {
818 flags
|= GET_OID_QUIETLY
;
821 if (opt_with_value(arg
, "--short", &arg
)) {
822 filter
&= ~(DO_FLAGS
|DO_NOREV
);
824 abbrev
= DEFAULT_ABBREV
;
827 abbrev
= strtoul(arg
, NULL
, 10);
828 if (abbrev
< MINIMUM_ABBREV
)
829 abbrev
= MINIMUM_ABBREV
;
830 else if (hexsz
<= abbrev
)
834 if (!strcmp(arg
, "--sq")) {
838 if (!strcmp(arg
, "--not")) {
839 show_type
^= REVERSED
;
842 if (!strcmp(arg
, "--symbolic")) {
843 symbolic
= SHOW_SYMBOLIC_ASIS
;
846 if (!strcmp(arg
, "--symbolic-full-name")) {
847 symbolic
= SHOW_SYMBOLIC_FULL
;
850 if (opt_with_value(arg
, "--abbrev-ref", &arg
)) {
852 abbrev_ref_strict
= warn_ambiguous_refs
;
854 if (!strcmp(arg
, "strict"))
855 abbrev_ref_strict
= 1;
856 else if (!strcmp(arg
, "loose"))
857 abbrev_ref_strict
= 0;
859 die(_("unknown mode for --abbrev-ref: %s"),
864 if (!strcmp(arg
, "--all")) {
865 for_each_ref(show_reference
, NULL
);
866 clear_ref_exclusions(&ref_excludes
);
869 if (skip_prefix(arg
, "--disambiguate=", &arg
)) {
870 for_each_abbrev(arg
, show_abbrev
, NULL
);
873 if (!strcmp(arg
, "--bisect")) {
874 for_each_fullref_in("refs/bisect/bad", show_reference
, NULL
);
875 for_each_fullref_in("refs/bisect/good", anti_reference
, NULL
);
878 if (opt_with_value(arg
, "--branches", &arg
)) {
879 if (ref_excludes
.hidden_refs_configured
)
880 return error(_("--exclude-hidden cannot be used together with --branches"));
881 handle_ref_opt(arg
, "refs/heads/");
884 if (opt_with_value(arg
, "--tags", &arg
)) {
885 if (ref_excludes
.hidden_refs_configured
)
886 return error(_("--exclude-hidden cannot be used together with --tags"));
887 handle_ref_opt(arg
, "refs/tags/");
890 if (skip_prefix(arg
, "--glob=", &arg
)) {
891 handle_ref_opt(arg
, NULL
);
894 if (opt_with_value(arg
, "--remotes", &arg
)) {
895 if (ref_excludes
.hidden_refs_configured
)
896 return error(_("--exclude-hidden cannot be used together with --remotes"));
897 handle_ref_opt(arg
, "refs/remotes/");
900 if (skip_prefix(arg
, "--exclude=", &arg
)) {
901 add_ref_exclusion(&ref_excludes
, arg
);
904 if (skip_prefix(arg
, "--exclude-hidden=", &arg
)) {
905 exclude_hidden_refs(&ref_excludes
, arg
);
908 if (!strcmp(arg
, "--show-toplevel")) {
909 const char *work_tree
= get_git_work_tree();
911 print_path(work_tree
, prefix
, format
, DEFAULT_UNMODIFIED
);
913 die(_("this operation must be run in a work tree"));
916 if (!strcmp(arg
, "--show-superproject-working-tree")) {
917 struct strbuf superproject
= STRBUF_INIT
;
918 if (get_superproject_working_tree(&superproject
))
919 print_path(superproject
.buf
, prefix
, format
, DEFAULT_UNMODIFIED
);
920 strbuf_release(&superproject
);
923 if (!strcmp(arg
, "--show-prefix")) {
930 if (!strcmp(arg
, "--show-cdup")) {
931 const char *pfx
= prefix
;
932 if (!is_inside_work_tree()) {
933 const char *work_tree
=
936 printf("%s\n", work_tree
);
940 pfx
= strchr(pfx
, '/');
949 if (!strcmp(arg
, "--git-dir") ||
950 !strcmp(arg
, "--absolute-git-dir")) {
951 const char *gitdir
= getenv(GIT_DIR_ENVIRONMENT
);
954 enum format_type wanted
= format
;
955 if (arg
[2] == 'g') { /* --git-dir */
957 print_path(gitdir
, prefix
, format
, DEFAULT_UNMODIFIED
);
961 print_path(".git", prefix
, format
, DEFAULT_UNMODIFIED
);
964 } else { /* --absolute-git-dir */
965 wanted
= FORMAT_CANONICAL
;
966 if (!gitdir
&& !prefix
)
969 struct strbuf realpath
= STRBUF_INIT
;
970 strbuf_realpath(&realpath
, gitdir
, 1);
972 strbuf_release(&realpath
);
979 strbuf_addf(&buf
, "%s%s.git", cwd
, len
&& cwd
[len
-1] != '/' ? "/" : "");
981 print_path(buf
.buf
, prefix
, wanted
, DEFAULT_CANONICAL
);
984 if (!strcmp(arg
, "--git-common-dir")) {
985 print_path(get_git_common_dir(), prefix
, format
, DEFAULT_RELATIVE_IF_SHARED
);
988 if (!strcmp(arg
, "--is-inside-git-dir")) {
989 printf("%s\n", is_inside_git_dir() ? "true"
993 if (!strcmp(arg
, "--is-inside-work-tree")) {
994 printf("%s\n", is_inside_work_tree() ? "true"
998 if (!strcmp(arg
, "--is-bare-repository")) {
999 printf("%s\n", is_bare_repository() ? "true"
1003 if (!strcmp(arg
, "--is-shallow-repository")) {
1005 is_repository_shallow(the_repository
) ? "true"
1009 if (!strcmp(arg
, "--shared-index-path")) {
1010 if (repo_read_index(the_repository
) < 0)
1011 die(_("Could not read the index"));
1012 if (the_index
.split_index
) {
1013 const struct object_id
*oid
= &the_index
.split_index
->base_oid
;
1014 const char *path
= git_path("sharedindex.%s", oid_to_hex(oid
));
1015 print_path(path
, prefix
, format
, DEFAULT_RELATIVE
);
1019 if (skip_prefix(arg
, "--since=", &arg
)) {
1020 show_datestring("--max-age=", arg
);
1023 if (skip_prefix(arg
, "--after=", &arg
)) {
1024 show_datestring("--max-age=", arg
);
1027 if (skip_prefix(arg
, "--before=", &arg
)) {
1028 show_datestring("--min-age=", arg
);
1031 if (skip_prefix(arg
, "--until=", &arg
)) {
1032 show_datestring("--min-age=", arg
);
1035 if (opt_with_value(arg
, "--show-object-format", &arg
)) {
1036 const char *val
= arg
? arg
: "storage";
1038 if (strcmp(val
, "storage") &&
1039 strcmp(val
, "input") &&
1040 strcmp(val
, "output"))
1041 die(_("unknown mode for --show-object-format: %s"),
1043 puts(the_hash_algo
->name
);
1046 if (!strcmp(arg
, "--end-of-options")) {
1047 seen_end_of_options
= 1;
1048 if (filter
& (DO_FLAGS
| DO_REVS
))
1052 if (show_flag(arg
) && verify
)
1053 die_no_single_rev(quiet
);
1057 /* Not a flag argument */
1058 if (try_difference(arg
))
1060 if (try_parent_shorthands(arg
))
1068 if (!get_oid_with_context(the_repository
, name
,
1069 flags
, &oid
, &unused
)) {
1073 show_rev(type
, &oid
, name
);
1077 die_no_single_rev(quiet
);
1079 die(_("bad revision '%s'"), arg
);
1081 if (!show_file(arg
, output_prefix
))
1083 verify_filename(prefix
, arg
, 1);
1085 strbuf_release(&buf
);
1087 if (revs_count
== 1) {
1088 show_rev(type
, &oid
, name
);
1090 } else if (revs_count
== 0 && show_default())
1092 die_no_single_rev(quiet
);