Skip to contentSkip to conversation

repo: add the field path.common-dir

PATCH New Pushkar Singh 1 participant 1 message Mar 1 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

PATCH 2/2 repo: add the field path.common-dir

Expose the repository common directory through a new path.common-dir field in git repo info.

This mirrors the information available via git rev-parse --common-dir and allows structured retrieval through the repo subcommand.

The value respects the --path-format flag.

---
 builtin/repo.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
builtin/repo.c +16 -0
index 8b4c7ae4cb..d42ac2478b 100644
@@ -88,6 +88,21 @@ static int get_path_git_dir(struct repository *repo, struct strbuf *buf,
 	return 0;
 }
 
+static int get_path_common_dir(struct repository *repo, struct strbuf *buf,
+				 const char *prefix,
+				 enum path_format_type format)
+{
+	const char *commondir = repo_get_common_dir(repo);
+
+	if (!commondir)
+		return error(_("unable to retrieve common directory"));
+
+	strbuf_add_path(buf, commondir, prefix, format,
+					PATH_DEFAULT_RELATIVE_IF_SHARED);
+
+	return 0;
+}
+
 static int get_references_format(struct repository *repo, struct strbuf *buf,
 				 const char *prefix UNUSED,
 				 enum path_format_type format UNUSED)
@@ -102,6 +117,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 },
+	{ "path.common-dir", get_path_common_dir },
 	{ "path.git-dir", get_path_git_dir },
 	{ "path.toplevel", get_path_toplevel },
 	{ "references.format", get_references_format },
Signature · 1 line
2.43.0