Re: [PATCH] repo: add paths.toplevel to repo info
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Apr 2, 2026, 17:38 UTC
- Message-ID
- <xmqqpl4hqn2w.fsf@gitster.g>
- In-Reply-To
- <pull.2264.git.git.1775150062407.gitgitgadget@gmail.com>
"Jayesh Daga via GitGitGadget" <gitgitgadget@gmail.com> writes:
Show 10 quoted lines
> +static int get_paths_toplevel(struct repository *repo, struct strbuf *buf)
> +{
> + const char *wt = repo_get_work_tree(repo);
> +
> + if (!wt)
> + return -1; /* match existing error style */
> +
> + strbuf_addstr(buf, wt);
> + return 0;
> +}Funny indentation. In our C codebase, one level of indent is one horizontal tab "\t".
Show 6 quoted lines
> @@ -87,6 +98,7 @@ static const struct repo_info_field repo_info_field[] = {
> { "layout.bare", get_layout_bare },
> { "layout.shallow", get_layout_shallow },
> { "object.format", get_object_format },
> + { "paths.toplevel", get_paths_toplevel },
> { "references.format", get_references_format },Instead of adding yet another one as people think of it, can we first take an inventory of what is available from the kitchen-sink options of "git rev-parse" and make a list, to be compared with what is available in repo_info_field[]? Add that correspondence table in a comment before the definition of this array, and it is perfectly OK if the right hand side on many rows say "missing", like
/*
* rev-parse --<opt> repo info <field>
*
* is-bare-repository layout.bare
* is-shallow-repository layout.shallow
* show-cdup <missing>
* show-prefix <missing>
* show-object-format object.format
* show-ref-format references.format
* ... more ...
*/There can be two classes of <missing>, ones that we want to have but haven't been implemented eyt, and others that we do not think we need.
Also, we may not want to limit the existing sources of information to "rev-parse", in which case lines of such a correspondence table may need to be grouped by where each piece of information is found elsewhere.
Show 29 quoted lines
> }; > > diff --git a/t/t1900-repo-info.sh b/t/t1900-repo-info.sh > index 39bb77dda0..470e06e8c2 100755 > --- a/t/t1900-repo-info.sh > +++ b/t/t1900-repo-info.sh > @@ -155,4 +155,20 @@ test_expect_success 'git repo info -h shows only repo info usage' ' > test_grep ! "git repo structure" actual > ' > > +test_expect_success 'repo info paths.toplevel' ' > + git repo info paths.toplevel >actual && > + echo "paths.toplevel=$(git rev-parse --show-toplevel)" >expected && > + test_cmp expected actual > +' > + > +test_expect_success 'repo info paths.toplevel (bare repo)' ' > + git init --bare bare.git && > + ( > + cd bare.git && > + git repo info paths.toplevel >actual && > + echo "paths.toplevel=" >expected && > + test_cmp expected actual > + ) > +' > + > test_done > > base-commit: 256554692df0685b45e60778b08802b720880c50