Re: [PATCH v5 06/28] Make git_path() aware of file relocation in $GIT_DIR

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, Mar 7, 2014 at 9:47 PM, Nguyễn Thái Ngọc Duy <pclouds@xxxxxxxxx> wrote:
> We allow the user to relocate certain paths out of $GIT_DIR via
> environment variables, e.g. GIT_OBJECT_DIRECTORY, GIT_INDEX_FILE and
> GIT_GRAFT_FILE. Callers are not supposed to use git_path() or
> git_pathdup() to get those paths. Instead they must use
> get_object_directory(), get_index_file() and get_graft_file()
> respectively. This is inconvenient and could be missed in review (for
> example, there's git_path("objects/info/alternates") somewhere in
> sha1_file.c).
>
> This patch makes git_path() and git_pathdup() understand those
> environment variables. So if you set GIT_OBJECT_DIRECTORY to /foo/bar,
> git_path("objects/abc") should return /foo/bar/abc. The same is done
> for the two remaining env variables.
>
> "git rev-parse --git-path" is the wrapper for script use.
>
> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@xxxxxxxxx>
> ---
>  Documentation/git-rev-parse.txt |  7 ++++++
>  builtin/rev-parse.c             |  7 ++++++
>  cache.h                         |  1 +
>  environment.c                   |  9 ++++++--
>  path.c                          | 49 +++++++++++++++++++++++++++++++++++++++--
>  t/t0060-path-utils.sh           | 19 ++++++++++++++++
>  6 files changed, 88 insertions(+), 4 deletions(-)
>
> diff --git a/Documentation/git-rev-parse.txt b/Documentation/git-rev-parse.txt
> index 0d2cdcd..46020d9 100644
> --- a/Documentation/git-rev-parse.txt
> +++ b/Documentation/git-rev-parse.txt
> @@ -232,6 +232,13 @@ print a message to stderr and exit with nonzero status.
>         repository.  If <path> is a gitfile then the resolved path
>         to the real repository is printed.
>
> +--git-path <path>::
> +       Resolve "$GIT_DIR/<path>" and takes other path relocation
> +       variables such as $GIT_OBJECT_DIRECTORY,
> +       $GIT_INDEX_FILE... into account. For example, if
> +       $GIT_OBJECT_DIRECTORY is set to /foo/bar then "git rev-parse
> +       --git-path objects/abc" returns /tmp/bar/abc.

s/tmp/foo/

> +
>  --show-cdup::
>         When the command is invoked from a subdirectory, show the
>         path of the top-level directory relative to the current
> diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c
> index aaeb611..e50bc65 100644
> --- a/builtin/rev-parse.c
> +++ b/builtin/rev-parse.c
> @@ -518,6 +518,13 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
>         for (i = 1; i < argc; i++) {
>                 const char *arg = argv[i];
>
> +               if (!strcmp(arg, "--git-path")) {
> +                       if (!argv[i + 1])
> +                               die("--git-path requires an argument");
> +                       puts(git_path("%s", argv[i + 1]));
> +                       i++;
> +                       continue;
> +               }
>                 if (as_is) {
>                         if (show_file(arg, output_prefix) && as_is < 2)
>                                 verify_filename(prefix, arg, 0);
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]