From: Junio C Hamano Date: Fri, 30 Aug 2013 17:08:12 +0000 (-0700) Subject: Merge branch 'rj/doc-rev-parse' X-Git-Tag: v1.8.5-rc0~205 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/e30db6dbcf28894a830bfd8a94e31a0b8eadc6e2?ds=inline;hp=-c Merge branch 'rj/doc-rev-parse' * rj/doc-rev-parse: rev-parse(1): logically group options rev-parse: remove restrictions on some options --- e30db6dbcf28894a830bfd8a94e31a0b8eadc6e2 diff --combined Documentation/git-rev-parse.txt index 2b126c0a77,ce186e9f06..d068a65377 --- a/Documentation/git-rev-parse.txt +++ b/Documentation/git-rev-parse.txt @@@ -24,9 -24,23 +24,23 @@@ distinguish between them OPTIONS ------- + + Operation Modes + ~~~~~~~~~~~~~~~ + + Each of these options must appear first on the command line. + --parseopt:: Use 'git rev-parse' in option parsing mode (see PARSEOPT section below). + --sq-quote:: + Use 'git rev-parse' in shell quoting mode (see SQ-QUOTE + section below). In contrast to the `--sq` option below, this + mode does only quoting. Nothing else is done to command input. + + Options for --parseopt + ~~~~~~~~~~~~~~~~~~~~~~ + --keep-dashdash:: Only meaningful in `--parseopt` mode. Tells the option parser to echo out the first `--` met instead of skipping it. @@@ -36,10 -50,8 +50,8 @@@ the first non-option argument. This can be used to parse sub-commands that take options themselves. - --sq-quote:: - Use 'git rev-parse' in shell quoting mode (see SQ-QUOTE - section below). In contrast to the `--sq` option below, this - mode does only quoting. Nothing else is done to command input. + Options for Filtering + ~~~~~~~~~~~~~~~~~~~~~ --revs-only:: Do not output flags and parameters not meant for @@@ -55,26 -67,13 +67,29 @@@ --no-flags:: Do not output flag parameters. + Options for Output + ~~~~~~~~~~~~~~~~~~ + --default :: If there is no parameter given by the user, use `` instead. +--prefix :: + Behave as if 'git rev-parse' was invoked from the `` + subdirectory of the working tree. Any relative filenames are + resolved as if they are prefixed by `` and will be printed + in that form. ++ +This can be used to convert arguments to a command run in a subdirectory +so that they can still be used after moving to the top-level of the +repository. For example: ++ +---- +prefix=$(git rev-parse --show-prefix) +cd "$(git rev-parse --show-toplevel)" +eval "set -- $(git rev-parse --sq --prefix "$prefix" "$@")" +---- + --verify:: Verify that exactly one parameter is provided, and that it can be turned into a raw 20-byte SHA-1 that can be used to @@@ -83,7 -82,7 +98,7 @@@ + If you want to make sure that the output actually names an object in your object database and/or can be used as a specific type of object -you require, you can add "^{type}" peeling operator to the parmeter. +you require, you can add "^{type}" peeling operator to the parameter. For example, `git rev-parse "$VAR^{commit}"` will make sure `$VAR` names an existing object that is a commit-ish (i.e. a commit, or an annotated tag that points at a commit). To make sure that `$VAR` @@@ -110,6 -109,17 +125,17 @@@ can be used strip '{caret}' prefix from the object names that already have one. + --abbrev-ref[=(strict|loose)]:: + A non-ambiguous short name of the objects name. + The option core.warnAmbiguousRefs is used to select the strict + abbreviation mode. + + --short:: + --short=number:: + Instead of outputting the full SHA-1 values of object names try to + abbreviate them to a shorter unique name. When no length is specified + 7 is used. The minimum length is 4. + --symbolic:: Usually the object names are output in SHA-1 form (with possible '{caret}' prefix); this option makes them output in a @@@ -123,16 -133,8 +149,8 @@@ unfortunately named tag "master"), and show them as full refnames (e.g. "refs/heads/master"). - --abbrev-ref[=(strict|loose)]:: - A non-ambiguous short name of the objects name. - The option core.warnAmbiguousRefs is used to select the strict - abbreviation mode. - - --disambiguate=:: - Show every object whose name begins with the given prefix. - The must be at least 4 hexadecimal digits long to - avoid listing each and every object in the repository by - mistake. + Options for Objects + ~~~~~~~~~~~~~~~~~~~ --all:: Show all refs found in `refs/`. @@@ -155,18 -157,20 +173,20 @@@ shown. If the pattern does not contai character (`?`, `*`, or `[`), it is turned into a prefix match by appending `/*`. - --show-toplevel:: - Show the absolute path of the top-level directory. + --disambiguate=:: + Show every object whose name begins with the given prefix. + The must be at least 4 hexadecimal digits long to + avoid listing each and every object in the repository by + mistake. - --show-prefix:: - When the command is invoked from a subdirectory, show the - path of the current directory relative to the top-level - directory. + Options for Files + ~~~~~~~~~~~~~~~~~ - --show-cdup:: - When the command is invoked from a subdirectory, show the - path of the top-level directory relative to the current - directory (typically a sequence of "../", or an empty string). + --local-env-vars:: + List the GIT_* environment variables that are local to the + repository (e.g. GIT_DIR or GIT_WORK_TREE, but not GIT_EDITOR). + Only the names of the variables are listed, not their value, + even if they are set. --git-dir:: Show `$GIT_DIR` if defined. Otherwise show the path to @@@ -188,17 -192,27 +208,27 @@@ print a message to stderr and exit wit --is-bare-repository:: When the repository is bare print "true", otherwise "false". - --local-env-vars:: - List the GIT_* environment variables that are local to the - repository (e.g. GIT_DIR or GIT_WORK_TREE, but not GIT_EDITOR). - Only the names of the variables are listed, not their value, - even if they are set. + --resolve-git-dir :: + Check if is a valid repository or a gitfile that + points at a valid repository, and print the location of the + repository. If is a gitfile then the resolved path + to the real repository is printed. - --short:: - --short=number:: - Instead of outputting the full SHA-1 values of object names try to - abbreviate them to a shorter unique name. When no length is specified - 7 is used. The minimum length is 4. + --show-cdup:: + When the command is invoked from a subdirectory, show the + path of the top-level directory relative to the current + directory (typically a sequence of "../", or an empty string). + + --show-prefix:: + When the command is invoked from a subdirectory, show the + path of the current directory relative to the top-level + directory. + + --show-toplevel:: + Show the absolute path of the top-level directory. + + Other Options + ~~~~~~~~~~~~~ --since=datestring:: --after=datestring:: @@@ -213,12 -227,6 +243,6 @@@ ...:: Flags and parameters to be parsed. - --resolve-git-dir :: - Check if is a valid repository or a gitfile that - points at a valid repository, and print the location of the - repository. If is a gitfile then the resolved path - to the real repository is printed. - include::revisions.txt[] diff --combined builtin/rev-parse.c index de894c7577,6c58a9fb22..c9aa28fd75 --- a/builtin/rev-parse.c +++ b/builtin/rev-parse.c @@@ -212,17 -212,11 +212,17 @@@ static void show_datestring(const char show(buffer); } -static int show_file(const char *arg) +static int show_file(const char *arg, int output_prefix) { show_default(); if ((filter & (DO_NONFLAGS|DO_NOREV)) == (DO_NONFLAGS|DO_NOREV)) { - show(arg); + if (output_prefix) { + const char *prefix = startup_info->prefix; + show(prefix_filename(prefix, + prefix ? strlen(prefix) : 0, + arg)); + } else + show(arg); return 1; } return 0; @@@ -476,7 -470,6 +476,7 @@@ N_("git rev-parse --parseopt [options] int cmd_rev_parse(int argc, const char **argv, const char *prefix) { int i, as_is = 0, verify = 0, quiet = 0, revs_count = 0, type = 0; + int output_prefix = 0; unsigned char sha1[20]; const char *name = NULL; @@@ -486,21 -479,6 +486,6 @@@ if (argc > 1 && !strcmp("--sq-quote", argv[1])) return cmd_sq_quote(argc - 2, argv + 2); - if (argc == 2 && !strcmp("--local-env-vars", argv[1])) { - int i; - for (i = 0; local_repo_env[i]; i++) - printf("%s\n", local_repo_env[i]); - return 0; - } - - if (argc > 2 && !strcmp(argv[1], "--resolve-git-dir")) { - const char *gitdir = resolve_gitdir(argv[2]); - if (!gitdir) - die("not a gitdir '%s'", argv[2]); - puts(gitdir); - return 0; - } - if (argc > 1 && !strcmp("-h", argv[1])) usage(builtin_rev_parse_usage); @@@ -510,7 -488,7 +495,7 @@@ const char *arg = argv[i]; if (as_is) { - if (show_file(arg) && as_is < 2) + if (show_file(arg, output_prefix) && as_is < 2) verify_filename(prefix, arg, 0); continue; } @@@ -534,7 -512,7 +519,7 @@@ as_is = 2; /* Pass on the "--" if we show anything but files.. */ if (filter & (DO_FLAGS | DO_REVS)) - show_file(arg); + show_file(arg, 0); continue; } if (!strcmp(arg, "--default")) { @@@ -542,13 -520,6 +527,13 @@@ i++; continue; } + if (!strcmp(arg, "--prefix")) { + prefix = argv[i+1]; + startup_info->prefix = prefix; + output_prefix = 1; + i++; + continue; + } if (!strcmp(arg, "--revs-only")) { filter &= ~DO_NOREV; continue; @@@ -661,6 -632,12 +646,12 @@@ for_each_remote_ref(show_reference, NULL); continue; } + if (!strcmp(arg, "--local-env-vars")) { + int i; + for (i = 0; local_repo_env[i]; i++) + printf("%s\n", local_repo_env[i]); + continue; + } if (!strcmp(arg, "--show-toplevel")) { const char *work_tree = get_git_work_tree(); if (work_tree) @@@ -711,6 -688,13 +702,13 @@@ printf("%s%s.git\n", cwd, len && cwd[len-1] != '/' ? "/" : ""); continue; } + if (!strcmp(arg, "--resolve-git-dir")) { + const char *gitdir = resolve_gitdir(argv[i+1]); + if (!gitdir) + die("not a gitdir '%s'", argv[i+1]); + puts(gitdir); + continue; + } if (!strcmp(arg, "--is-inside-git-dir")) { printf("%s\n", is_inside_git_dir() ? "true" : "false"); @@@ -768,7 -752,7 +766,7 @@@ if (verify) die_no_single_rev(quiet); as_is = 1; - if (!show_file(arg)) + if (!show_file(arg, output_prefix)) continue; verify_filename(prefix, arg, 1); }