Re: [PATCH v3 2/2] rev-parse: fix some options when executed from subpath of main tree

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

 



On Fri, May 6, 2016 at 9:35 AM, Michael Rappazzo <rappazzo@xxxxxxxxx> wrote:
> Executing `git-rev-parse` with `--git-common-dir`, `--git-path <path>`,
> or `--shared-index-path` from the root of the main worktree results in
> a relative path to the git dir.
>
> When executed from a subdirectory of the main tree, it can incorrectly
> return a path which starts 'sub/path/.git'.  Change this to return the
> proper relative path to the git directory.
>
> Related tests marked to expect failure are updated to expect success
>
> Signed-off-by: Michael Rappazzo <rappazzo@xxxxxxxxx>
> ---
> diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c
> @@ -564,10 +564,13 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
>                 if (!strcmp(arg, "--git-path")) {
> +                       struct strbuf sb = STRBUF_INIT;
>                         if (!argv[i + 1])
>                                 die("--git-path requires an argument");
> -                       puts(git_path("%s", argv[i + 1]));
> -                       i++;
> +
> +                       puts(relative_path(xstrfmt("%s/%s", get_git_dir(), argv[++i]),
> +                               prefix, &sb));

This is leaking the result of xstrfmt().

> +                       strbuf_release(&sb);
>                         continue;
>                 }
> @@ -811,7 +815,12 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
>                                 if (the_index.split_index) {
>                                         const unsigned char *sha1 = the_index.split_index->base_sha1;
> -                                       puts(git_path("sharedindex.%s", sha1_to_hex(sha1)));
> +                                       struct strbuf sb = STRBUF_INIT;
> +
> +                                       puts(relative_path(
> +                                               xstrfmt("%s/sharedindex.%s", get_git_dir(), sha1_to_hex(sha1)),
> +                                               prefix, &sb));

Likewise leaking xstrfmt().

> +                                       strbuf_release(&sb);
>                                 }
>                                 continue;
>                         }
--
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]