[PATCH 07/13] url-parse: define string to component converter fn
- From
Matheus Afonso Martins Moreira via GitGitGadget <gitgitgadget@gmail.com>
- Date
- Apr 28, 2024, 22:30 UTC
- Message-ID
- <eb9ef8a17bd123b2611d5df0fab4364fbff4b277.1714343461.git.gitgitgadget@gmail.com>
- In-Reply-To
- <pull.1715.git.git.1714343461.gitgitgadget@gmail.com>
From: Matheus Afonso Martins Moreira <matheus@matheusmoreira.com>
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 <matheus@matheusmoreira.com> --- 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