Subject: [PATCH 07/13] url-parse: define string to component converter fn

From: "Matheus Afonso Martins Moreira via GitGitGadget" <[email-masked]>
Date: Sun, 28 Apr 2024 22:30:55 +0000

From: Matheus Afonso Martins Moreira <[email-masked]>

Converts a git URL component name to its corresponding
enumeration value so that it can be conveniently used
internally by the url-parse command.

Signed-off-by: Matheus Afonso Martins Moreira <[email-masked]>
---
 builtin/url-parse.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/builtin/url-parse.c b/builtin/url-parse.c
index b8ac46dcdeb..15923460a78 100644
--- a/builtin/url-parse.c
+++ b/builtin/url-parse.c
@@ -32,6 +32,23 @@ static void parse_or_die(const char *url, struct url_info *info)
 	}
 }
 
+static enum url_component get_component_or_die(const char *arg)
+{
+	if (!strcmp("path", arg))
+		return URL_PATH;
+	if (!strcmp("host", arg))
+		return URL_HOST;
+	if (!strcmp("protocol", arg))
+		return URL_PROTOCOL;
+	if (!strcmp("user", arg))
+		return URL_USER;
+	if (!strcmp("password", arg))
+		return URL_PASSWORD;
+	if (!strcmp("port", arg))
+		return URL_PORT;
+	die("invalid git URL component '%s'", arg);
+}
+
 static char *extract(enum url_component component, struct url_info *info)
 {
 	size_t offset, length;
-- 
gitgitgadget