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 (dwim_ref(name
, strlen(name
), &discard
, &full
, 0)) {
148 * Not found -- not a ref. We could
149 * emit "name" here, but symbolic-full
150 * users are interested in finding the
151 * refs spelled in full, and they would
152 * need to filter non-refs if we did so.
157 full
= shorten_unambiguous_ref(full
,
159 show_with_type(type
, full
);
161 default: /* ambiguous */
162 error("refname '%s' is ambiguous", name
);
167 show_with_type(type
, name
);
171 show_with_type(type
, find_unique_abbrev(oid
, abbrev
));
173 show_with_type(type
, oid_to_hex(oid
));
176 /* Output a flag, only if filter allows it. */
177 static int show_flag(const char *arg
)
179 if (!(filter
& DO_FLAGS
))
181 if (filter
& (is_rev_argument(arg
) ? DO_REVS
: DO_NOREV
)) {
188 static int show_default(void)
193 struct object_id oid
;
196 if (!get_oid(s
, &oid
)) {
197 show_rev(NORMAL
, &oid
, s
);
204 static int show_reference(const char *refname
, const struct object_id
*oid
,
205 int flag UNUSED
, void *cb_data UNUSED
)
207 if (ref_excluded(&ref_excludes
, refname
))
209 show_rev(NORMAL
, oid
, refname
);
213 static int anti_reference(const char *refname
, const struct object_id
*oid
,
214 int flag UNUSED
, void *cb_data UNUSED
)
216 show_rev(REVERSED
, oid
, refname
);
220 static int show_abbrev(const struct object_id
*oid
, void *cb_data
)
222 show_rev(NORMAL
, oid
, NULL
);
226 static void show_datestring(const char *flag
, const char *datestr
)
230 /* date handling requires both flags and revs */
231 if ((filter
& (DO_FLAGS
| DO_REVS
)) != (DO_FLAGS
| DO_REVS
))
233 buffer
= xstrfmt("%s%"PRItime
, flag
, approxidate(datestr
));
238 static int show_file(const char *arg
, int output_prefix
)
241 if ((filter
& (DO_NONFLAGS
|DO_NOREV
)) == (DO_NONFLAGS
|DO_NOREV
)) {
243 const char *prefix
= startup_info
->prefix
;
244 char *fname
= prefix_filename(prefix
, arg
);
254 static int try_difference(const char *arg
)
257 struct object_id start_oid
;
258 struct object_id end_oid
;
262 static const char head_by_default
[] = "HEAD";
264 if (!(dotdot
= strstr(arg
, "..")))
268 symmetric
= (*end
== '.');
274 end
= head_by_default
;
276 start
= head_by_default
;
278 if (start
== head_by_default
&& end
== head_by_default
&&
281 * Just ".."? That is not a range but the
282 * pathspec for the parent directory.
288 if (!get_oid_committish(start
, &start_oid
) && !get_oid_committish(end
, &end_oid
)) {
289 show_rev(NORMAL
, &end_oid
, end
);
290 show_rev(symmetric
? NORMAL
: REVERSED
, &start_oid
, start
);
292 struct commit_list
*exclude
;
293 struct commit
*a
, *b
;
294 a
= lookup_commit_reference(the_repository
, &start_oid
);
295 b
= lookup_commit_reference(the_repository
, &end_oid
);
300 exclude
= get_merge_bases(a
, b
);
302 struct commit
*commit
= pop_commit(&exclude
);
303 show_rev(REVERSED
, &commit
->object
.oid
, NULL
);
313 static int try_parent_shorthands(const char *arg
)
316 struct object_id oid
;
317 struct commit
*commit
;
318 struct commit_list
*parents
;
321 int include_parents
= 0;
322 int exclude_parent
= 0;
324 if ((dotdot
= strstr(arg
, "^!"))) {
328 } else if ((dotdot
= strstr(arg
, "^@"))) {
332 } else if ((dotdot
= strstr(arg
, "^-"))) {
338 exclude_parent
= strtoul(dotdot
+ 2, &end
, 10);
339 if (*end
!= '\0' || !exclude_parent
)
346 if (get_oid_committish(arg
, &oid
) ||
347 !(commit
= lookup_commit_reference(the_repository
, &oid
))) {
352 if (exclude_parent
&&
353 exclude_parent
> commit_list_count(commit
->parents
)) {
359 show_rev(NORMAL
, &oid
, arg
);
360 for (parents
= commit
->parents
, parent_number
= 1;
362 parents
= parents
->next
, parent_number
++) {
365 if (exclude_parent
&& parent_number
!= exclude_parent
)
369 name
= xstrfmt("%s^%d", arg
, parent_number
);
370 show_rev(include_parents
? NORMAL
: REVERSED
,
371 &parents
->item
->object
.oid
, name
);
379 static int parseopt_dump(const struct option
*o
, const char *arg
, int unset
)
381 struct strbuf
*parsed
= o
->value
;
383 strbuf_addf(parsed
, " --no-%s", o
->long_name
);
384 else if (o
->short_name
&& (o
->long_name
== NULL
|| !stuck_long
))
385 strbuf_addf(parsed
, " -%c", o
->short_name
);
387 strbuf_addf(parsed
, " --%s", o
->long_name
);
390 strbuf_addch(parsed
, ' ');
391 else if (o
->long_name
)
392 strbuf_addch(parsed
, '=');
393 sq_quote_buf(parsed
, arg
);
398 static const char *skipspaces(const char *s
)
405 static char *findspace(const char *s
)
413 static int cmd_parseopt(int argc
, const char **argv
, const char *prefix
)
415 static int keep_dashdash
= 0, stop_at_non_option
= 0;
416 static char const * const parseopt_usage
[] = {
417 N_("git rev-parse --parseopt [<options>] -- [<args>...]"),
420 static struct option parseopt_opts
[] = {
421 OPT_BOOL(0, "keep-dashdash", &keep_dashdash
,
422 N_("keep the `--` passed as an arg")),
423 OPT_BOOL(0, "stop-at-non-option", &stop_at_non_option
,
424 N_("stop parsing after the "
425 "first non-option argument")),
426 OPT_BOOL(0, "stuck-long", &stuck_long
,
427 N_("output in stuck long form")),
430 static const char * const flag_chars
= "*=?!";
432 struct strbuf sb
= STRBUF_INIT
, parsed
= STRBUF_INIT
;
433 const char **usage
= NULL
;
434 struct option
*opts
= NULL
;
435 int onb
= 0, osz
= 0, unb
= 0, usz
= 0;
437 strbuf_addstr(&parsed
, "set --");
438 argc
= parse_options(argc
, argv
, prefix
, parseopt_opts
, parseopt_usage
,
439 PARSE_OPT_KEEP_DASHDASH
);
440 if (argc
< 1 || strcmp(argv
[0], "--"))
441 usage_with_options(parseopt_usage
, parseopt_opts
);
443 /* get the usage up to the first line with a -- on it */
445 if (strbuf_getline(&sb
, stdin
) == EOF
)
446 die(_("premature end of input"));
447 ALLOC_GROW(usage
, unb
+ 1, usz
);
448 if (!strcmp("--", sb
.buf
)) {
450 die(_("no usage string given before the `--' separator"));
454 usage
[unb
++] = strbuf_detach(&sb
, NULL
);
457 /* parse: (<short>|<short>,<long>|<long>)[*=?!]*<arghint>? SP+ <help> */
458 while (strbuf_getline(&sb
, stdin
) != EOF
) {
466 ALLOC_GROW(opts
, onb
+ 1, osz
);
467 memset(opts
+ onb
, 0, sizeof(opts
[onb
]));
470 help
= findspace(sb
.buf
);
471 if (!help
|| sb
.buf
== help
) {
472 o
->type
= OPTION_GROUP
;
473 o
->help
= xstrdup(skipspaces(sb
.buf
));
479 o
->type
= OPTION_CALLBACK
;
480 o
->help
= xstrdup(skipspaces(help
+1));
482 o
->flags
= PARSE_OPT_NOARG
;
483 o
->callback
= &parseopt_dump
;
486 s
= strpbrk(sb
.buf
, flag_chars
);
491 die(_("missing opt-spec before option flags"));
493 if (s
- sb
.buf
== 1) /* short option only */
494 o
->short_name
= *sb
.buf
;
495 else if (sb
.buf
[1] != ',') /* long option only */
496 o
->long_name
= xmemdupz(sb
.buf
, s
- sb
.buf
);
498 o
->short_name
= *sb
.buf
;
499 o
->long_name
= xmemdupz(sb
.buf
+ 2, s
- sb
.buf
- 2);
506 o
->flags
&= ~PARSE_OPT_NOARG
;
509 o
->flags
&= ~PARSE_OPT_NOARG
;
510 o
->flags
|= PARSE_OPT_OPTARG
;
513 o
->flags
|= PARSE_OPT_NONEG
;
516 o
->flags
|= PARSE_OPT_HIDDEN
;
524 o
->argh
= xmemdupz(s
, help
- s
);
528 /* put an OPT_END() */
529 ALLOC_GROW(opts
, onb
+ 1, osz
);
530 memset(opts
+ onb
, 0, sizeof(opts
[onb
]));
531 argc
= parse_options(argc
, argv
, prefix
, opts
, usage
,
532 (keep_dashdash
? PARSE_OPT_KEEP_DASHDASH
: 0) |
533 (stop_at_non_option
? PARSE_OPT_STOP_AT_NON_OPTION
: 0) |
534 PARSE_OPT_SHELL_EVAL
);
536 strbuf_addstr(&parsed
, " --");
537 sq_quote_argv(&parsed
, argv
);
539 strbuf_release(&parsed
);
543 static int cmd_sq_quote(int argc
, const char **argv
)
545 struct strbuf buf
= STRBUF_INIT
;
548 sq_quote_argv(&buf
, argv
);
549 printf("%s\n", buf
.buf
);
550 strbuf_release(&buf
);
555 static void die_no_single_rev(int quiet
)
560 die(_("Needed a single revision"));
563 static const char builtin_rev_parse_usage
[] =
564 N_("git rev-parse --parseopt [<options>] -- [<args>...]\n"
565 " or: git rev-parse --sq-quote [<arg>...]\n"
566 " or: git rev-parse [<options>] [<arg>...]\n"
568 "Run \"git rev-parse --parseopt -h\" for more information on the first usage.");
571 * Parse "opt" or "opt=<value>", setting value respectively to either
572 * NULL or the string after "=".
574 static int opt_with_value(const char *arg
, const char *opt
, const char **value
)
576 if (skip_prefix(arg
, opt
, &arg
)) {
589 static void handle_ref_opt(const char *pattern
, const char *prefix
)
592 for_each_glob_ref_in(show_reference
, pattern
, prefix
, NULL
);
594 for_each_ref_in(prefix
, show_reference
, NULL
);
595 clear_ref_exclusions(&ref_excludes
);
599 /* We would like a relative path. */
601 /* We would like a canonical absolute path. */
603 /* We would like the default behavior. */
608 /* Our default is a relative path. */
610 /* Our default is a relative path if there's a shared root. */
611 DEFAULT_RELATIVE_IF_SHARED
,
612 /* Our default is a canonical absolute path. */
614 /* Our default is not to modify the item. */
618 static void print_path(const char *path
, const char *prefix
, enum format_type format
, enum default_type def
)
622 * We don't ever produce a relative path if prefix is NULL, so set the
623 * prefix to the current directory so that we can produce a relative
624 * path whenever possible. If we're using RELATIVE_IF_SHARED mode, then
625 * we want an absolute path unless the two share a common prefix, so don't
626 * set it in that case, since doing so causes a relative path to always
627 * be produced if possible.
629 if (!prefix
&& (format
!= FORMAT_DEFAULT
|| def
!= DEFAULT_RELATIVE_IF_SHARED
))
630 prefix
= cwd
= xgetcwd();
631 if (format
== FORMAT_DEFAULT
&& def
== DEFAULT_UNMODIFIED
) {
633 } else if (format
== FORMAT_RELATIVE
||
634 (format
== FORMAT_DEFAULT
&& def
== DEFAULT_RELATIVE
)) {
636 * In order for relative_path to work as expected, we need to
637 * make sure that both paths are absolute paths. If we don't,
638 * we can end up with an unexpected absolute path that the user
641 struct strbuf buf
= STRBUF_INIT
, realbuf
= STRBUF_INIT
, prefixbuf
= STRBUF_INIT
;
642 if (!is_absolute_path(path
)) {
643 strbuf_realpath_forgiving(&realbuf
, path
, 1);
646 if (!is_absolute_path(prefix
)) {
647 strbuf_realpath_forgiving(&prefixbuf
, prefix
, 1);
648 prefix
= prefixbuf
.buf
;
650 puts(relative_path(path
, prefix
, &buf
));
651 strbuf_release(&buf
);
652 strbuf_release(&realbuf
);
653 strbuf_release(&prefixbuf
);
654 } else if (format
== FORMAT_DEFAULT
&& def
== DEFAULT_RELATIVE_IF_SHARED
) {
655 struct strbuf buf
= STRBUF_INIT
;
656 puts(relative_path(path
, prefix
, &buf
));
657 strbuf_release(&buf
);
659 struct strbuf buf
= STRBUF_INIT
;
660 strbuf_realpath_forgiving(&buf
, path
, 1);
662 strbuf_release(&buf
);
667 int cmd_rev_parse(int argc
, const char **argv
, const char *prefix
)
669 int i
, as_is
= 0, verify
= 0, quiet
= 0, revs_count
= 0, type
= 0;
670 int did_repo_setup
= 0;
671 int has_dashdash
= 0;
672 int output_prefix
= 0;
673 struct object_id oid
;
674 unsigned int flags
= 0;
675 const char *name
= NULL
;
676 struct object_context unused
;
677 struct strbuf buf
= STRBUF_INIT
;
678 const int hexsz
= the_hash_algo
->hexsz
;
679 int seen_end_of_options
= 0;
680 enum format_type format
= FORMAT_DEFAULT
;
682 if (argc
> 1 && !strcmp("--parseopt", argv
[1]))
683 return cmd_parseopt(argc
- 1, argv
+ 1, prefix
);
685 if (argc
> 1 && !strcmp("--sq-quote", argv
[1]))
686 return cmd_sq_quote(argc
- 2, argv
+ 2);
688 if (argc
> 1 && !strcmp("-h", argv
[1]))
689 usage(builtin_rev_parse_usage
);
691 for (i
= 1; i
< argc
; i
++) {
692 if (!strcmp(argv
[i
], "--")) {
698 /* No options; just report on whether we're in a git repo or not. */
700 setup_git_directory();
701 git_config(git_default_config
, NULL
);
705 for (i
= 1; i
< argc
; i
++) {
706 const char *arg
= argv
[i
];
709 if (show_file(arg
, output_prefix
) && as_is
< 2)
710 verify_filename(prefix
, arg
, 0);
714 if (!seen_end_of_options
) {
715 if (!strcmp(arg
, "--local-env-vars")) {
717 for (i
= 0; local_repo_env
[i
]; i
++)
718 printf("%s\n", local_repo_env
[i
]);
721 if (!strcmp(arg
, "--resolve-git-dir")) {
722 const char *gitdir
= argv
[++i
];
724 die(_("--resolve-git-dir requires an argument"));
725 gitdir
= resolve_gitdir(gitdir
);
727 die(_("not a gitdir '%s'"), argv
[i
]);
733 /* The rest of the options require a git repository. */
734 if (!did_repo_setup
) {
735 prefix
= setup_git_directory();
736 git_config(git_default_config
, NULL
);
739 prepare_repo_settings(the_repository
);
740 the_repository
->settings
.command_requires_full_index
= 0;
743 if (!strcmp(arg
, "--")) {
745 /* Pass on the "--" if we show anything but files.. */
746 if (filter
& (DO_FLAGS
| DO_REVS
))
751 if (!seen_end_of_options
&& *arg
== '-') {
752 if (!strcmp(arg
, "--git-path")) {
754 die(_("--git-path requires an argument"));
756 print_path(git_path("%s", argv
[i
+ 1]), prefix
,
758 DEFAULT_RELATIVE_IF_SHARED
);
762 if (!strcmp(arg
,"-n")) {
764 die(_("-n requires an argument"));
765 if ((filter
& DO_FLAGS
) && (filter
& DO_REVS
)) {
771 if (starts_with(arg
, "-n")) {
772 if ((filter
& DO_FLAGS
) && (filter
& DO_REVS
))
776 if (opt_with_value(arg
, "--path-format", &arg
)) {
778 die(_("--path-format requires an argument"));
779 if (!strcmp(arg
, "absolute")) {
780 format
= FORMAT_CANONICAL
;
781 } else if (!strcmp(arg
, "relative")) {
782 format
= FORMAT_RELATIVE
;
784 die(_("unknown argument to --path-format: %s"), arg
);
788 if (!strcmp(arg
, "--default")) {
791 die(_("--default requires an argument"));
794 if (!strcmp(arg
, "--prefix")) {
797 die(_("--prefix requires an argument"));
798 startup_info
->prefix
= prefix
;
802 if (!strcmp(arg
, "--revs-only")) {
806 if (!strcmp(arg
, "--no-revs")) {
810 if (!strcmp(arg
, "--flags")) {
811 filter
&= ~DO_NONFLAGS
;
814 if (!strcmp(arg
, "--no-flags")) {
818 if (!strcmp(arg
, "--verify")) {
819 filter
&= ~(DO_FLAGS
|DO_NOREV
);
823 if (!strcmp(arg
, "--quiet") || !strcmp(arg
, "-q")) {
825 flags
|= GET_OID_QUIETLY
;
828 if (opt_with_value(arg
, "--short", &arg
)) {
829 filter
&= ~(DO_FLAGS
|DO_NOREV
);
831 abbrev
= DEFAULT_ABBREV
;
834 abbrev
= strtoul(arg
, NULL
, 10);
835 if (abbrev
< MINIMUM_ABBREV
)
836 abbrev
= MINIMUM_ABBREV
;
837 else if (hexsz
<= abbrev
)
841 if (!strcmp(arg
, "--sq")) {
845 if (!strcmp(arg
, "--not")) {
846 show_type
^= REVERSED
;
849 if (!strcmp(arg
, "--symbolic")) {
850 symbolic
= SHOW_SYMBOLIC_ASIS
;
853 if (!strcmp(arg
, "--symbolic-full-name")) {
854 symbolic
= SHOW_SYMBOLIC_FULL
;
857 if (opt_with_value(arg
, "--abbrev-ref", &arg
)) {
859 abbrev_ref_strict
= warn_ambiguous_refs
;
861 if (!strcmp(arg
, "strict"))
862 abbrev_ref_strict
= 1;
863 else if (!strcmp(arg
, "loose"))
864 abbrev_ref_strict
= 0;
866 die(_("unknown mode for --abbrev-ref: %s"),
871 if (!strcmp(arg
, "--all")) {
872 for_each_ref(show_reference
, NULL
);
873 clear_ref_exclusions(&ref_excludes
);
876 if (skip_prefix(arg
, "--disambiguate=", &arg
)) {
877 for_each_abbrev(arg
, show_abbrev
, NULL
);
880 if (!strcmp(arg
, "--bisect")) {
881 for_each_fullref_in("refs/bisect/bad", show_reference
, NULL
);
882 for_each_fullref_in("refs/bisect/good", anti_reference
, NULL
);
885 if (opt_with_value(arg
, "--branches", &arg
)) {
886 if (ref_excludes
.hidden_refs_configured
)
887 return error(_("--exclude-hidden cannot be used together with --branches"));
888 handle_ref_opt(arg
, "refs/heads/");
891 if (opt_with_value(arg
, "--tags", &arg
)) {
892 if (ref_excludes
.hidden_refs_configured
)
893 return error(_("--exclude-hidden cannot be used together with --tags"));
894 handle_ref_opt(arg
, "refs/tags/");
897 if (skip_prefix(arg
, "--glob=", &arg
)) {
898 handle_ref_opt(arg
, NULL
);
901 if (opt_with_value(arg
, "--remotes", &arg
)) {
902 if (ref_excludes
.hidden_refs_configured
)
903 return error(_("--exclude-hidden cannot be used together with --remotes"));
904 handle_ref_opt(arg
, "refs/remotes/");
907 if (skip_prefix(arg
, "--exclude=", &arg
)) {
908 add_ref_exclusion(&ref_excludes
, arg
);
911 if (skip_prefix(arg
, "--exclude-hidden=", &arg
)) {
912 exclude_hidden_refs(&ref_excludes
, arg
);
915 if (!strcmp(arg
, "--show-toplevel")) {
916 const char *work_tree
= get_git_work_tree();
918 print_path(work_tree
, prefix
, format
, DEFAULT_UNMODIFIED
);
920 die(_("this operation must be run in a work tree"));
923 if (!strcmp(arg
, "--show-superproject-working-tree")) {
924 struct strbuf superproject
= STRBUF_INIT
;
925 if (get_superproject_working_tree(&superproject
))
926 print_path(superproject
.buf
, prefix
, format
, DEFAULT_UNMODIFIED
);
927 strbuf_release(&superproject
);
930 if (!strcmp(arg
, "--show-prefix")) {
937 if (!strcmp(arg
, "--show-cdup")) {
938 const char *pfx
= prefix
;
939 if (!is_inside_work_tree()) {
940 const char *work_tree
=
943 printf("%s\n", work_tree
);
947 pfx
= strchr(pfx
, '/');
956 if (!strcmp(arg
, "--git-dir") ||
957 !strcmp(arg
, "--absolute-git-dir")) {
958 const char *gitdir
= getenv(GIT_DIR_ENVIRONMENT
);
961 enum format_type wanted
= format
;
962 if (arg
[2] == 'g') { /* --git-dir */
964 print_path(gitdir
, prefix
, format
, DEFAULT_UNMODIFIED
);
968 print_path(".git", prefix
, format
, DEFAULT_UNMODIFIED
);
971 } else { /* --absolute-git-dir */
972 wanted
= FORMAT_CANONICAL
;
973 if (!gitdir
&& !prefix
)
976 struct strbuf realpath
= STRBUF_INIT
;
977 strbuf_realpath(&realpath
, gitdir
, 1);
979 strbuf_release(&realpath
);
986 strbuf_addf(&buf
, "%s%s.git", cwd
, len
&& cwd
[len
-1] != '/' ? "/" : "");
988 print_path(buf
.buf
, prefix
, wanted
, DEFAULT_CANONICAL
);
991 if (!strcmp(arg
, "--git-common-dir")) {
992 print_path(get_git_common_dir(), prefix
, format
, DEFAULT_RELATIVE_IF_SHARED
);
995 if (!strcmp(arg
, "--is-inside-git-dir")) {
996 printf("%s\n", is_inside_git_dir() ? "true"
1000 if (!strcmp(arg
, "--is-inside-work-tree")) {
1001 printf("%s\n", is_inside_work_tree() ? "true"
1005 if (!strcmp(arg
, "--is-bare-repository")) {
1006 printf("%s\n", is_bare_repository() ? "true"
1010 if (!strcmp(arg
, "--is-shallow-repository")) {
1012 is_repository_shallow(the_repository
) ? "true"
1016 if (!strcmp(arg
, "--shared-index-path")) {
1017 if (repo_read_index(the_repository
) < 0)
1018 die(_("Could not read the index"));
1019 if (the_index
.split_index
) {
1020 const struct object_id
*oid
= &the_index
.split_index
->base_oid
;
1021 const char *path
= git_path("sharedindex.%s", oid_to_hex(oid
));
1022 print_path(path
, prefix
, format
, DEFAULT_RELATIVE
);
1026 if (skip_prefix(arg
, "--since=", &arg
)) {
1027 show_datestring("--max-age=", arg
);
1030 if (skip_prefix(arg
, "--after=", &arg
)) {
1031 show_datestring("--max-age=", arg
);
1034 if (skip_prefix(arg
, "--before=", &arg
)) {
1035 show_datestring("--min-age=", arg
);
1038 if (skip_prefix(arg
, "--until=", &arg
)) {
1039 show_datestring("--min-age=", arg
);
1042 if (opt_with_value(arg
, "--show-object-format", &arg
)) {
1043 const char *val
= arg
? arg
: "storage";
1045 if (strcmp(val
, "storage") &&
1046 strcmp(val
, "input") &&
1047 strcmp(val
, "output"))
1048 die(_("unknown mode for --show-object-format: %s"),
1050 puts(the_hash_algo
->name
);
1053 if (!strcmp(arg
, "--end-of-options")) {
1054 seen_end_of_options
= 1;
1055 if (filter
& (DO_FLAGS
| DO_REVS
))
1059 if (show_flag(arg
) && verify
)
1060 die_no_single_rev(quiet
);
1064 /* Not a flag argument */
1065 if (try_difference(arg
))
1067 if (try_parent_shorthands(arg
))
1075 if (!get_oid_with_context(the_repository
, name
,
1076 flags
, &oid
, &unused
)) {
1080 show_rev(type
, &oid
, name
);
1084 die_no_single_rev(quiet
);
1086 die(_("bad revision '%s'"), arg
);
1088 if (!show_file(arg
, output_prefix
))
1090 verify_filename(prefix
, arg
, 1);
1092 strbuf_release(&buf
);
1094 if (revs_count
== 1) {
1095 show_rev(type
, &oid
, name
);
1097 } else if (revs_count
== 0 && show_default())
1099 die_no_single_rev(quiet
);