git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
Eric Sunshine <sunshine@sunshineco.com>
Date
May 10, 2016, 07:38 UTC
Message-ID
<CAPig+cQ9+=JcNguvuFN9GwHf1M1aLDNeyY8dJQLMkEGSXrU6Tg@mail.gmail.com>
In-Reply-To
<1462541720-79553-3-git-send-email-rappazzo@gmail.com>
On Fri, May 6, 2016 at 9:35 AM, Michael Rappazzo <rappazzo@gmail.com> wrote:
Show 23 quoted lines
> 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@gmail.com>
> ---
> 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().
Show 12 quoted lines
> +                       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;
>                         }
Previous: Michael Rappazzo
Message 8 of 8 in “rev-parse: fix some options when executed from subpath of main tree”
  1. 0/2 [PATCH v3 0/2] rev-parse: fix some options when executed from subpath of main treeMichael Rappazzo, May 6, 2016
  2. 1/2 rev-parse tests: add tests executed from a subdirectoryMichael Rappazzo, May 6, 2016
  3. Junio C HamanoMay 6, 2016
  4. Mike RappazzoMay 7, 2016
  5. Junio C HamanoMay 8, 2016
  6. Junio C HamanoMay 8, 2016
  7. 2/2 rev-parse: fix some options when executed from subpath of main treeMichael Rappazzo, May 6, 2016
  8. Eric SunshineMay 10, 2016

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.