Skip to contentSkip to conversation

repo: add more path keys to git repo info

PATCH Superseded K Jayatheerth 6 participants 135 messages Jul 16 – Nov 16 Documentation Page 2 of 2

lore
Share & tools
lore
#129 lore raw

PATCH v9 4/5 repo: add path.index with absolute and relative suffixes

In reply to K Jayatheerth

The repository index is a fundamental component used by Git and related tooling to track the working tree state. Scripts that interact with the index currently retrieve its location by invoking
git rev-parse --git-path index.

Introduce path.index.absolute and path.index.relative keys to git repo info. This exposes the index file location as a scriptable config-like key using standard format rules, allowing scripts to retrieve it through the same interface as other repository path information.

---
 Documentation/git-repo.adoc | 12 ++++++++++++
 builtin/repo.c              | 18 ++++++++++++++++++
 t/t1900-repo-info.sh        | 23 +++++++++++++++++++++++
 3 files changed, 53 insertions(+)
Documentation/git-repo.adoc +12 -0
index 8cb154513a..c515e9372f 100644
@@ -119,6 +119,18 @@ values that they return:
 `path.gitdir.relative`::
 	The path to the Git repository directory relative to the current working directory.
 
+`path.index.absolute`::
+	The canonical absolute path to the repository's current index file.
+	Respects the `GIT_INDEX_FILE` environment override. Returns the
+	configured index path even if the repository is bare or the file does
+	not exist.
+
+`path.index.relative`::
+	The path to the repository's current index file relative to the current
+	working directory. Respects the `GIT_INDEX_FILE` environment override.
+	Returns the configured index path even if the repository is bare or the
+	file does not exist.
+
 `path.superprojectworkingtree.absolute`::
 	The canonical absolute path to the working tree root of the superproject
 	if the current repository is an initialized submodule. Outputs an empty
builtin/repo.c +18 -0
index 8b461ea226..eeaee98c75 100644
@@ -122,6 +122,22 @@ static int get_path_gitdir_relative(struct repository *repo, struct strbuf *buf)
 	return 0;
 }
 
+static int get_path_index_absolute(struct repository *repo, struct strbuf *buf)
+{
+	const char *index_file = repo_get_index_file(repo);
+
+	format_path(buf, index_file, "", PATH_FORMAT_CANONICAL);
+	return 0;
+}
+
+static int get_path_index_relative(struct repository *repo, struct strbuf *buf)
+{
+	const char *index_file = repo_get_index_file(repo);
+
+	format_path(buf, index_file, repo->prefix, PATH_FORMAT_RELATIVE);
+	return 0;
+}
+
 static int get_path_superprojectworkingtree_absolute(struct repository *repo, struct strbuf *buf)
 {
 	struct strbuf superproject = STRBUF_INIT;
@@ -182,6 +198,8 @@ static const struct repo_info_field repo_info_field[] = {
 	{ "path.commondir.relative", get_path_commondir_relative },
 	{ "path.gitdir.absolute", get_path_gitdir_absolute },
 	{ "path.gitdir.relative", get_path_gitdir_relative },
+	{ "path.index.absolute", get_path_index_absolute },
+	{ "path.index.relative", get_path_index_relative },
 	{ "path.superprojectworkingtree.absolute", get_path_superprojectworkingtree_absolute },
 	{ "path.superprojectworkingtree.relative", get_path_superprojectworkingtree_relative },
 	{ "path.workingtree.absolute", get_path_workingtree_absolute },
t/t1900-repo-info.sh +23 -0
index 582f643dd1..46c92d4e43 100755
@@ -213,6 +213,29 @@ test_repo_info_path 'gitdir with explicit GIT_DIR' 'gitdir' \
 	'.git' \
 	'GIT_DIR="../.git" && export GIT_DIR'
 
+test_repo_info_path 'index standard' 'index' '.git/index'
+
+test_repo_info_path 'index with GIT_INDEX_FILE override' 'index' \
+	'custom-index-file' \
+	'GIT_INDEX_FILE="$ROOT/custom-index-file" && export GIT_INDEX_FILE'
+
+test_expect_success 'path.index in a bare repository returns default index location' '
+	test_when_finished "rm -rf bare.git" &&
+	git init --bare bare.git &&
+	(
+		cd bare.git &&
+		ROOT="$(test-tool path-utils real_path .)" &&
+
+		echo "path.index.absolute=$ROOT/index" >expect.abs &&
+		git repo info path.index.absolute >actual.abs &&
+		test_cmp expect.abs actual.abs &&
+
+		echo "path.index.relative=index" >expect.rel &&
+		git repo info path.index.relative >actual.rel &&
+		test_cmp expect.rel actual.rel
+	)
+'
+
 test_expect_success 'path.superprojectworkingtree absolute and relative' '
 	test_when_finished "rm -rf sub super" &&
 	git init sub &&
Signature · 1 line
2.56.0-rc2
#130 lore raw

PATCH v9 5/5 repo: add path.prefix

In reply to K Jayatheerth

Scripts sometimes need the path from the repository's working tree root to the current working directory. While this information can be derived through existing Git commands, git repo info does not currently expose it as a scriptable key.

Introduce the path.prefix key to git repo info. The key returns the path from the working tree root to the current working directory, returning the empty string when invoked from the working tree root.

---
 Documentation/git-repo.adoc |  5 +++++
 builtin/repo.c              | 11 +++++++++++
 t/t1900-repo-info.sh        | 23 +++++++++++++++++++++++
 3 files changed, 39 insertions(+)
Documentation/git-repo.adoc +5 -0
index c515e9372f..17992c7a67 100644
@@ -131,6 +131,11 @@ values that they return:
 	Returns the configured index path even if the repository is bare or the
 	file does not exist.
 
+`path.prefix`::
+	The path from the root of the working tree to the current working
+	directory. Returns the empty string when the current working directory
+	is the root of the working tree.
+
 `path.superprojectworkingtree.absolute`::
 	The canonical absolute path to the working tree root of the superproject
 	if the current repository is an initialized submodule. Outputs an empty
builtin/repo.c +11 -0
index eeaee98c75..87c5743246 100644
@@ -100,6 +100,16 @@ static int get_path_commondir_relative(struct repository *repo, struct strbuf *b
 	return 0;
 }
 
+static int get_path_prefix(struct repository *repo, struct strbuf *buf)
+{
+	/*
+	 * repo->prefix is NULL when the current working directory is
+	 * the worktree root.
+	 */
+	strbuf_addstr(buf, repo->prefix ? repo->prefix : "");
+	return 0;
+}
+
 static int get_path_gitdir_absolute(struct repository *repo, struct strbuf *buf)
 {
 	const char *git_dir = repo_get_git_dir(repo);
@@ -200,6 +210,7 @@ static const struct repo_info_field repo_info_field[] = {
 	{ "path.gitdir.relative", get_path_gitdir_relative },
 	{ "path.index.absolute", get_path_index_absolute },
 	{ "path.index.relative", get_path_index_relative },
+	{ "path.prefix", get_path_prefix },
 	{ "path.superprojectworkingtree.absolute", get_path_superprojectworkingtree_absolute },
 	{ "path.superprojectworkingtree.relative", get_path_superprojectworkingtree_relative },
 	{ "path.workingtree.absolute", get_path_workingtree_absolute },
t/t1900-repo-info.sh +23 -0
index 46c92d4e43..d0631a8f3b 100755
@@ -207,6 +207,29 @@ test_repo_info_path 'commondir with only GIT_DIR' 'commondir' \
 	'.git' \
 	'GIT_DIR="../.git" && export GIT_DIR'
 
+test_expect_success 'path.prefix at repository root' '
+	test_when_finished "rm -rf repo" &&
+	git init repo &&
+	(
+		cd repo &&
+		echo "path.prefix=" >expect &&
+		git repo info path.prefix >actual &&
+		test_cmp expect actual
+	)
+'
+
+test_expect_success 'path.prefix in subdirectory' '
+	test_when_finished "rm -rf repo" &&
+	git init repo &&
+	mkdir -p repo/sub/dir &&
+	(
+		cd repo/sub/dir &&
+		echo "path.prefix=sub/dir/" >expect &&
+		git repo info path.prefix >actual &&
+		test_cmp expect actual
+	)
+'
+
 test_repo_info_path 'gitdir standard' 'gitdir' '.git'
 
 test_repo_info_path 'gitdir with explicit GIT_DIR' 'gitdir' \
Signature · 1 line
2.56.0-rc2
#131 lore raw

Re: [GSoC Patch v9 0/5] repo: add path keys to repo info

In reply to K Jayatheerth

Hi K Jayatheerth

Quoted 10 lines · K Jayatheerth

Changes since v8:
- Dropped path.hooks and path.cdup.
- Renamed path.toplevel.* to path.workingtree.* to align with the standard "working tree" glossary term while avoiding hyphens in configuration variable names.
- Renamed path.superproject-root.* to path.superprojectworkingtree.* to provide a descriptive name for scripts while avoiding hyphens.
- Renamed path.git-prefix to path.prefix to shorten it and avoid hyphens.

The range-diff looks good. It is a shame we're still creating a new repository for each test when the majority of the tests could happily run in the repository that the test framework creates for us. No one else seems to mind that, even though it makes our test suite slower than it needs to be, so I'd be happy if this is merged as-is.

Thanks

Phillip

Quoted 475 lines

Range-diff against v8:
1: 27b9811163 ! 1: 6cb242828b repo: add path.toplevel with absolute and relative suffix formatting

     @@ Metadata
      Author: K Jayatheerth <[email protected]>
      
       ## Commit message ##
     -    repo: add path.toplevel with absolute and relative suffix formatting
     +    repo: add path.workingtree with absolute and relative suffix formatting
      
          Scripts frequently need to find the root directory of a repository's
          working tree. Currently, this requires using `git rev-parse --show-toplevel`
          or inferring it from other repository information.
      
     -    Introduce `path.toplevel.absolute` and `path.toplevel.relative` keys
     +    Introduce `path.workingtree.absolute` and `path.workingtree.relative` keys
          to `git repo info`. This allows scripts to retrieve the top-level
          working tree path in a predictable, strictly formatted manner without
          relying on `rev-parse`.
     @@ Documentation/git-repo.adoc: values that they return:
       `path.gitdir.relative`::
       	The path to the Git repository directory relative to the current working directory.
       
     -+`path.toplevel.absolute`::
     ++`path.workingtree.absolute`::
      +	The canonical absolute path to the top-level directory of the
      +	repository's working tree. Outputs an empty string if the repository
      +	is bare.
      +
     -+`path.toplevel.relative`::
     ++`path.workingtree.relative`::
      +	The path to the top-level directory of the repository's working
      +	tree relative to the current working directory. Outputs an empty
      +	string if the repository is bare.
     @@ builtin/repo.c: static int get_path_gitdir_relative(struct repository *repo, str
       	return 0;
       }
       
     -+static int get_path_toplevel_absolute(struct repository *repo, struct strbuf *buf)
     ++static int get_path_workingtree_absolute(struct repository *repo, struct strbuf *buf)
      +{
      +	const char *work_tree = repo_get_work_tree(repo);
      +
     @@ builtin/repo.c: static int get_path_gitdir_relative(struct repository *repo, str
      +	return 0;
      +}
      +
     -+static int get_path_toplevel_relative(struct repository *repo, struct strbuf *buf)
     ++static int get_path_workingtree_relative(struct repository *repo, struct strbuf *buf)
      +{
      +	const char *work_tree = repo_get_work_tree(repo);
      +
     @@ builtin/repo.c: static const struct repo_info_field repo_info_field[] = {
       	{ "path.commondir.relative", get_path_commondir_relative },
       	{ "path.gitdir.absolute", get_path_gitdir_absolute },
       	{ "path.gitdir.relative", get_path_gitdir_relative },
     -+	{ "path.toplevel.absolute", get_path_toplevel_absolute },
     -+	{ "path.toplevel.relative", get_path_toplevel_relative },
     ++	{ "path.workingtree.absolute", get_path_workingtree_absolute },
     ++	{ "path.workingtree.relative", get_path_workingtree_relative },
       	{ "references.format", get_references_format },
       };
       
     @@ t/t1900-repo-info.sh: test_repo_info_path 'gitdir with explicit GIT_DIR' 'gitdir
       	'.git' \
       	'GIT_DIR="../.git" && export GIT_DIR'
       
     -+test_expect_success 'path.toplevel absolute and relative' '
     ++test_expect_success 'path.workingtree absolute and relative' '
      +	test_when_finished "rm -rf repo" &&
      +	git init repo &&
      +	(
     @@ t/t1900-repo-info.sh: test_repo_info_path 'gitdir with explicit GIT_DIR' 'gitdir
      +
      +		ROOT="$(test-tool path-utils real_path ..)" &&
      +
     -+		echo "path.toplevel.absolute=$ROOT" >expect.abs &&
     -+		git repo info path.toplevel.absolute >actual.abs &&
     ++		echo "path.workingtree.absolute=$ROOT" >expect.abs &&
     ++		git repo info path.workingtree.absolute >actual.abs &&
      +		test_cmp expect.abs actual.abs &&
      +
     -+		echo "path.toplevel.relative=../" >expect.rel &&
     -+		git repo info path.toplevel.relative >actual.rel &&
     ++		echo "path.workingtree.relative=../" >expect.rel &&
     ++		git repo info path.workingtree.relative >actual.rel &&
      +		test_cmp expect.rel actual.rel
      +	)
      +'
      +
     -+test_expect_success 'path.toplevel absolute and relative in a bare repository' '
     ++test_expect_success 'path.workingtree absolute and relative in a bare repository' '
      +	test_when_finished "rm -rf bare.git" &&
      +	git init --bare bare.git &&
      +	(
      +		cd bare.git &&
      +
     -+		echo "path.toplevel.absolute=" >expect.abs &&
     -+		git repo info path.toplevel.absolute >actual.abs &&
     ++		echo "path.workingtree.absolute=" >expect.abs &&
     ++		git repo info path.workingtree.absolute >actual.abs &&
      +		test_cmp expect.abs actual.abs &&
      +
     -+		echo "path.toplevel.relative=" >expect.rel &&
     -+		git repo info path.toplevel.relative >actual.rel &&
     ++		echo "path.workingtree.relative=" >expect.rel &&
     ++		git repo info path.workingtree.relative >actual.rel &&
      +		test_cmp expect.rel actual.rel
      +	)
      +'
2:  2274dd8be2 = 2:  9da5ce8a69 submodule: use repository to find superproject
3:  34c54cdafd ! 3:  deaf3ae42e repo: add path.superproject-root with absolute and relative suffixes
     @@ Metadata
      Author: K Jayatheerth <[email protected]>
      
       ## Commit message ##
     -    repo: add path.superproject-root with absolute and relative suffixes
     +    repo: add path.superprojectworkingtree with absolute and relative suffixes
      
          Scripts working in multi-repository setups often need to identify the
          top-level working tree of a superproject from within a submodule.
          Currently, this is only exposed via `git rev-parse
          --show-superproject-working-tree`.
      
     -    Introduce `path.superproject-root.absolute` and
     -    `path.superproject-root.relative` keys to `git repo info`.
     +    Introduce `path.superprojectworkingtree.absolute` and
     +    `path.superprojectworkingtree.relative` keys to `git repo info`.
          This exposes the core submodule context via a scriptable config-like key
          using standard format rules.
      
     @@ Documentation/git-repo.adoc: values that they return:
       `path.gitdir.relative`::
       	The path to the Git repository directory relative to the current working directory.
       
     -+`path.superproject-root.absolute`::
     ++`path.superprojectworkingtree.absolute`::
      +	The canonical absolute path to the working tree root of the superproject
      +	if the current repository is an initialized submodule. Outputs an empty
      +	string if not in a submodule.
      +
     -+`path.superproject-root.relative`::
     ++`path.superprojectworkingtree.relative`::
      +	The path to the working tree root of the superproject relative to the
      +	current working directory if the current repository is an initialized
      +	submodule. Outputs an empty string if not in a submodule.
      +
     - `path.toplevel.absolute`::
     + `path.workingtree.absolute`::
       	The canonical absolute path to the top-level directory of the
       	repository's working tree. Outputs an empty string if the repository
      
     @@ builtin/repo.c: static int get_path_gitdir_relative(struct repository *repo, str
       	return 0;
       }
       
     -+static int get_path_superproject_absolute(struct repository *repo, struct strbuf *buf)
     ++static int get_path_superprojectworkingtree_absolute(struct repository *repo, struct strbuf *buf)
      +{
      +	struct strbuf superproject = STRBUF_INIT;
      +
     @@ builtin/repo.c: static int get_path_gitdir_relative(struct repository *repo, str
      +	return 0;
      +}
      +
     -+static int get_path_superproject_relative(struct repository *repo, struct strbuf *buf)
     ++static int get_path_superprojectworkingtree_relative(struct repository *repo, struct strbuf *buf)
      +{
      +	struct strbuf superproject = STRBUF_INIT;
      +
     @@ builtin/repo.c: static int get_path_gitdir_relative(struct repository *repo, str
      +	return 0;
      +}
      +
     - static int get_path_toplevel_absolute(struct repository *repo, struct strbuf *buf)
     + static int get_path_workingtree_absolute(struct repository *repo, struct strbuf *buf)
       {
       	const char *work_tree = repo_get_work_tree(repo);
      @@ builtin/repo.c: static const struct repo_info_field repo_info_field[] = {
       	{ "path.commondir.relative", get_path_commondir_relative },
       	{ "path.gitdir.absolute", get_path_gitdir_absolute },
       	{ "path.gitdir.relative", get_path_gitdir_relative },
     -+	{ "path.superproject-root.absolute", get_path_superproject_absolute },
     -+	{ "path.superproject-root.relative", get_path_superproject_relative },
     - 	{ "path.toplevel.absolute", get_path_toplevel_absolute },
     - 	{ "path.toplevel.relative", get_path_toplevel_relative },
     ++	{ "path.superprojectworkingtree.absolute", get_path_superprojectworkingtree_absolute },
     ++	{ "path.superprojectworkingtree.relative", get_path_superprojectworkingtree_relative },
     + 	{ "path.workingtree.absolute", get_path_workingtree_absolute },
     + 	{ "path.workingtree.relative", get_path_workingtree_relative },
       	{ "references.format", get_references_format },
      
       ## t/t1900-repo-info.sh ##
     @@ t/t1900-repo-info.sh: test_repo_info_path 'gitdir with explicit GIT_DIR' 'gitdir
       	'.git' \
       	'GIT_DIR="../.git" && export GIT_DIR'
       
     -+test_expect_success 'path.superproject-root absolute and relative' '
     ++test_expect_success 'path.superprojectworkingtree absolute and relative' '
      +	test_when_finished "rm -rf sub super" &&
      +	git init sub &&
      +	test_commit -C sub initial &&
     @@ t/t1900-repo-info.sh: test_repo_info_path 'gitdir with explicit GIT_DIR' 'gitdir
      +		cd sub &&
      +		ROOT="$(test-tool path-utils real_path ..)" &&
      +
     -+		echo "path.superproject-root.absolute=$ROOT" >expect.abs &&
     -+		git repo info path.superproject-root.absolute >actual.abs &&
     ++		echo "path.superprojectworkingtree.absolute=$ROOT" >expect.abs &&
     ++		git repo info path.superprojectworkingtree.absolute >actual.abs &&
      +		test_cmp expect.abs actual.abs &&
      +
     -+		echo "path.superproject-root.relative=../" >expect.rel &&
     -+		git repo info path.superproject-root.relative >actual.rel &&
     ++		echo "path.superprojectworkingtree.relative=../" >expect.rel &&
     ++		git repo info path.superprojectworkingtree.relative >actual.rel &&
      +		test_cmp expect.rel actual.rel
      +	)
      +'
      +
     -+test_expect_success 'path.superproject-root returns empty when not in a submodule' '
     ++test_expect_success 'path.superprojectworkingtree returns empty when not in a submodule' '
      +	test_when_finished "rm -rf repo" &&
      +	git init repo &&
      +	(
      +		cd repo &&
      +
     -+		echo "path.superproject-root.absolute=" >expect.abs &&
     -+		git repo info path.superproject-root.absolute >actual.abs &&
     ++		echo "path.superprojectworkingtree.absolute=" >expect.abs &&
     ++		git repo info path.superprojectworkingtree.absolute >actual.abs &&
      +		test_cmp expect.abs actual.abs &&
      +
     -+		echo "path.superproject-root.relative=" >expect.rel &&
     -+		git repo info path.superproject-root.relative >actual.rel &&
     ++		echo "path.superprojectworkingtree.relative=" >expect.rel &&
     ++		git repo info path.superprojectworkingtree.relative >actual.rel &&
      +		test_cmp expect.rel actual.rel
      +	)
      +'
      +
     - test_expect_success 'path.toplevel absolute and relative' '
     + test_expect_success 'path.workingtree absolute and relative' '
       	test_when_finished "rm -rf repo" &&
       	git init repo &&
4:  985403c7b3 < -:  ---------- repo: add path.hooks with absolute and relative suffixes
5:  486836ae52 ! 4:  de9e189714 repo: add path.index with absolute and relative suffixes

@@ Commit message

## Documentation/git-repo.adoc ##
@@ Documentation/git-repo.adoc: values that they return:
- working directory. Respects the core.hooksPath configuration. If
- core.hooksPath is set to /dev/null, that value is returned unchanged.
+ path.gitdir.relative::
+ The path to the Git repository directory relative to the current working directory.

+path.index.absolute::
+ The canonical absolute path to the repository's current index file.
@@ Documentation/git-repo.adoc: values that they return:
+ Returns the configured index path even if the repository is bare or the
+ file does not exist.
+
- path.superproject-root.absolute::
+ path.superprojectworkingtree.absolute::
The canonical absolute path to the working tree root of the superproject if the current repository is an initialized submodule. Outputs an empty

## builtin/repo.c ##
-@@ builtin/repo.c: static int get_path_hooks_relative(struct repository *repo, struct strbuf *buf) +@@ builtin/repo.c: static int get_path_gitdir_relative(struct repository *repo, struct strbuf *buf)
return 0;
}

@@ builtin/repo.c: static int get_path_hooks_relative(struct repository *repo, stru
+ return 0;
+}
+
- static int get_path_superproject_absolute(struct repository *repo, struct strbuf *buf)
+ static int get_path_superprojectworkingtree_absolute(struct repository *repo, struct strbuf *buf) {
struct strbuf superproject = STRBUF_INIT;
@@ builtin/repo.c: static const struct repo_info_field repo_info_field[] = {
+ { "path.commondir.relative", get_path_commondir_relative },
+ { "path.gitdir.absolute", get_path_gitdir_absolute },
{ "path.gitdir.relative", get_path_gitdir_relative },
- { "path.hooks.absolute", get_path_hooks_absolute },
- { "path.hooks.relative", get_path_hooks_relative },
+ { "path.index.absolute", get_path_index_absolute },
+ { "path.index.relative", get_path_index_relative },
- { "path.superproject-root.absolute", get_path_superproject_absolute },
- { "path.superproject-root.relative", get_path_superproject_relative },
- { "path.toplevel.absolute", get_path_toplevel_absolute },
+ { "path.superprojectworkingtree.absolute", get_path_superprojectworkingtree_absolute },
+ { "path.superprojectworkingtree.relative", get_path_superprojectworkingtree_relative },
+ { "path.workingtree.absolute", get_path_workingtree_absolute },

## t/t1900-repo-info.sh ##
-@@ t/t1900-repo-info.sh: test_expect_success 'hooks with core.hooksPath=/dev/null' '
- )
- '
+@@ t/t1900-repo-info.sh: test_repo_info_path 'gitdir with explicit GIT_DIR' 'gitdir' \
+ '.git' \
+ 'GIT_DIR="../.git" && export GIT_DIR'

+test_repo_info_path 'index standard' 'index' '.git/index'
+
@@ t/t1900-repo-info.sh: test_expect_success 'hooks with core.hooksPath=/dev/null'
+ )
+'
+
- test_expect_success 'path.superproject-root absolute and relative' '
+ test_expect_success 'path.superprojectworkingtree absolute and relative' ' test_when_finished "rm -rf sub super" &&
git init sub &&

6:  91a8dc3ab1 < -:  ---------- repo: add path.git-prefix
7:  84a9fb4060 ! 5:  97035f59f4 repo: add path.cdup
     @@ Metadata
      Author: K Jayatheerth <[email protected]>
      
       ## Commit message ##
     -    repo: add path.cdup
     +    repo: add path.prefix
      
     -    Scripts sometimes need the relative path from the current working
     -    directory to the repository's working tree root (cdup). While this
     -    information can be retrieved through `git rev-parse --show-cdup`,
     -    `git repo info` does not currently expose it as a scriptable key.
     +    Scripts sometimes need the path from the repository's working tree root
     +    to the current working directory. While this information can be derived
     +    through existing Git commands, `git repo info` does not currently expose
     +    it as a scriptable key.
      
     -    Introduce the `path.cdup` key to `git repo info`. The key returns the
     -    path from the current working directory to the root of the working tree,
     +    Introduce the `path.prefix` key to `git repo info`. The key returns
     +    the path from the working tree root to the current working directory,
          returning the empty string when invoked from the working tree root.
      
          Mentored-by: Justin Tobler <[email protected]>
     @@ Commit message
      
       ## Documentation/git-repo.adoc ##
      @@ Documentation/git-repo.adoc: values that they return:
     - `object.format`::
     - 	The object format (hash algorithm) used in the repository.
     + 	Returns the configured index path even if the repository is bare or the
     + 	file does not exist.
       
     -+`path.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).
     ++`path.prefix`::
     ++	The path from the root of the working tree to the current working
     ++	directory. Returns the empty string when the current working directory
     ++	is the root of the working tree.
      +
     - `path.commondir.absolute`::
     - 	The canonical absolute path to the Git repository's common
     - 	directory (the shared `.git` directory containing objects,
     + `path.superprojectworkingtree.absolute`::
     + 	The canonical absolute path to the working tree root of the superproject
     + 	if the current repository is an initialized submodule. Outputs an empty
      
       ## builtin/repo.c ##
     -@@ builtin/repo.c: static int get_object_format(struct repository *repo, struct strbuf *buf)
     +@@ builtin/repo.c: static int get_path_commondir_relative(struct repository *repo, struct strbuf *b
       	return 0;
       }
       
     -+static int get_path_cdup(struct repository *repo, struct strbuf *buf)
     ++static int get_path_prefix(struct repository *repo, struct strbuf *buf)
      +{
     -+	const char *pfx = repo->prefix;
     -+
     -+	if (!is_inside_work_tree(repo)) {
     -+		const char *worktree = repo_get_work_tree(repo);
     -+
     -+		if (worktree)
     -+			strbuf_addstr(buf, worktree);
     -+		return 0;
     -+	}
     -+
     -+	while (pfx) {
     -+		pfx = strchr(pfx, '/');
     -+		if (pfx) {
     -+			pfx++;
     -+			strbuf_addstr(buf, "../");
     -+		}
     -+	}
     ++	/*
     ++	 * repo->prefix is NULL when the current working directory is
     ++	 * the worktree root.
     ++	 */
     ++	strbuf_addstr(buf, repo->prefix ? repo->prefix : "");
      +	return 0;
      +}
      +
     - static int get_path_commondir_absolute(struct repository *repo, struct strbuf *buf)
     + static int get_path_gitdir_absolute(struct repository *repo, struct strbuf *buf)
       {
     - 	const char *common_dir = repo_get_common_dir(repo);
     + 	const char *git_dir = repo_get_git_dir(repo);
      @@ builtin/repo.c: static const struct repo_info_field repo_info_field[] = {
     - 	{ "layout.bare", get_layout_bare },
     - 	{ "layout.shallow", get_layout_shallow },
     - 	{ "object.format", get_object_format },
     -+	{ "path.cdup", get_path_cdup },
     - 	{ "path.commondir.absolute", get_path_commondir_absolute },
     - 	{ "path.commondir.relative", get_path_commondir_relative },
     - 	{ "path.git-prefix", get_path_git_prefix },
     + 	{ "path.gitdir.relative", get_path_gitdir_relative },
     + 	{ "path.index.absolute", get_path_index_absolute },
     + 	{ "path.index.relative", get_path_index_relative },
     ++	{ "path.prefix", get_path_prefix },
     + 	{ "path.superprojectworkingtree.absolute", get_path_superprojectworkingtree_absolute },
     + 	{ "path.superprojectworkingtree.relative", get_path_superprojectworkingtree_relative },
     + 	{ "path.workingtree.absolute", get_path_workingtree_absolute },
      
       ## t/t1900-repo-info.sh ##
      @@ t/t1900-repo-info.sh: test_repo_info_path 'commondir with only GIT_DIR' 'commondir' \
       	'.git' \
       	'GIT_DIR="../.git" && export GIT_DIR'
       
     -+test_expect_success 'path.cdup at repository root' '
     ++test_expect_success 'path.prefix at repository root' '
      +	test_when_finished "rm -rf repo" &&
      +	git init repo &&
      +	(
      +		cd repo &&
     -+		echo "path.cdup=" >expect &&
     -+		git repo info path.cdup >actual &&
     ++		echo "path.prefix=" >expect &&
     ++		git repo info path.prefix >actual &&
      +		test_cmp expect actual
      +	)
      +'
      +
     -+test_expect_success 'path.cdup in subdirectory' '
     ++test_expect_success 'path.prefix in subdirectory' '
      +	test_when_finished "rm -rf repo" &&
      +	git init repo &&
      +	mkdir -p repo/sub/dir &&
      +	(
      +		cd repo/sub/dir &&
     -+		echo "path.cdup=../../" >expect &&
     -+		git repo info path.cdup >actual &&
     ++		echo "path.prefix=sub/dir/" >expect &&
     ++		git repo info path.prefix >actual &&
      +		test_cmp expect actual
      +	)
      +'
      +
     -+test_expect_success 'path.cdup cwd outside the working tree' '
     -+	test_when_finished "rm -rf repo" &&
     -+	mkdir -p repo/tmp/x &&
     -+	(
     -+		cd repo &&
     -+		git init test &&
     -+		echo "path.cdup=$(pwd)/tmp/x" >test/expect &&
     -+		cd test &&
     -+		GIT_WORK_TREE=../tmp/x &&
     -+		export GIT_WORK_TREE &&
     -+		GIT_DIR=$(pwd)/.git &&
     -+		export GIT_DIR &&
     -+		git repo info path.cdup >actual &&
     -+		test_cmp expect actual
     -+	)
     -+'
     -+
     - test_expect_success 'path.git-prefix at repository root' '
     - 	test_when_finished "rm -rf repo" &&
     - 	git init repo &&
     + test_repo_info_path 'gitdir standard' 'gitdir' '.git'
     +
     + test_repo_info_path 'gitdir with explicit GIT_DIR' 'gitdir' \
#132 lore raw

Re: [GSoC Patch v9 0/5] repo: add path keys to repo info

Quoted 21 lines · Phillip Wood

Hi K Jayatheerth

Quoted 10 lines · K Jayatheerth

Changes since v8:
- Dropped path.hooks and path.cdup.
- Renamed path.toplevel.* to path.workingtree.* to align with the standard "working tree" glossary term while avoiding hyphens in configuration variable names.
- Renamed path.superproject-root.* to path.superprojectworkingtree.* to provide a descriptive name for scripts while avoiding hyphens.
- Renamed path.git-prefix to path.prefix to shorten it and avoid hyphens.

The range-diff looks good. It is a shame we're still creating a new repository for each test when the majority of the tests could happily run in the repository that the test framework creates for us. No one else seems to mind that, even though it makes our test suite slower than it needs to be, so I'd be happy if this is merged as-is.

Quoted 3 lines

Thanks

Phillip

Whoops, apologies for missing that, I made a checklist for this reroll, read your
note about the tests, and completely forgot to add it to the list :)

Also there are some newly arised questions about this in my mind:

- I am currently writing a follow-up series to consolidate the overlapping logic between repo and rev-parse, and I plan to combine and clean up the tests there as well.
- Three path.* keys were already merged in an earlier round, so updating those tests would require a separate commit anyway.

That said, I'm open to feedback and happy to switch the tests in this series to run in
a single repository if you think it's worth doing now.

Thank you,

- K Jayatheerth

#133 lore raw

Re: [GSoC Patch v9 0/5] repo: add path keys to repo info

Quoted 19 lines · K Jayatheerth
Quoted 12 lines · Phillip Wood
Quoted 10 lines · K Jayatheerth

Changes since v8:
- Dropped path.hooks and path.cdup.
- Renamed path.toplevel.* to path.workingtree.* to align with the standard "working tree" glossary term while avoiding hyphens in configuration variable names.
- Renamed path.superproject-root.* to path.superprojectworkingtree.* to provide a descriptive name for scripts while avoiding hyphens.
- Renamed path.git-prefix to path.prefix to shorten it and avoid hyphens.

Quoted 6 lines

The range-diff looks good. It is a shame we're still creating a new repository for each test when the majority of the tests could happily run in the repository that the test framework creates for us. No one else seems to mind that, even though it makes our test suite slower than it needs to be, so I'd be happy if this is merged as-is.

Quoted 3 lines

Whoops, apologies for missing that, I made a checklist for this reroll, read your
note about the tests, and completely forgot to add it to the list :)

Not to worry, it is easily done

Quoted 11 lines

Also there are some newly arised questions about this in my mind:

- I am currently writing a follow-up series to consolidate the overlapping logic between repo and rev-parse, and I plan to combine and clean up the tests there as well.
- Three path.* keys were already merged in an earlier round, so updating those tests would require a separate commit anyway.

That said, I'm open to feedback and happy to switch the tests in this series to run in
a single repository if you think it's worth doing now.

If you're planning some test cleanups anyway then I'm happy for the tests here to be cleaned up by a future series. I'd do whatever you think is easiest for you.

Thanks

Phillip

#134 lore raw

Re: [GSoC Patch v9 0/5] repo: add path keys to repo info

Hey Phillip,

Quoted 35 lines · Phillip Wood
Quoted 19 lines · K Jayatheerth
Quoted 12 lines · Phillip Wood
Quoted 10 lines · K Jayatheerth

Changes since v8:
- Dropped path.hooks and path.cdup.
- Renamed path.toplevel.* to path.workingtree.* to align with the standard "working tree" glossary term while avoiding hyphens in configuration variable names.
- Renamed path.superproject-root.* to path.superprojectworkingtree.* to provide a descriptive name for scripts while avoiding hyphens.
- Renamed path.git-prefix to path.prefix to shorten it and avoid hyphens.

Quoted 6 lines

The range-diff looks good. It is a shame we're still creating a new repository for each test when the majority of the tests could happily run in the repository that the test framework creates for us. No one else seems to mind that, even though it makes our test suite slower than it needs to be, so I'd be happy if this is merged as-is.

Quoted 3 lines

Whoops, apologies for missing that, I made a checklist for this reroll, read your
note about the tests, and completely forgot to add it to the list :)

Not to worry, it is easily done

Quoted 8 lines

Also there are some newly arised questions about this in my mind:

- I am currently writing a follow-up series to consolidate the overlapping logic between repo and rev-parse, and I plan to combine and clean up the tests there as well.
- Three path.* keys were already merged in an earlier round, so updating those tests would require a separate commit anyway.

Quoted 7 lines
Quoted 3 lines

That said, I'm open to feedback and happy to switch the tests in this series to run in
a single repository if you think it's worth doing now.

If you're planning some test cleanups anyway then I'm happy for the tests here to be cleaned up by a future series. I'd do whatever you think is easiest for you.

Thank you! The easiest in my opinion would be to directly combine the tests and optimize them there.

Quoted 3 lines

Thanks

Phillip

Regards,

- K Jayatheerth