[PATCH 11/13] url-parse: output URL components selected by user
- From
Matheus Afonso Martins Moreira via GitGitGadget <gitgitgadget@gmail.com>
- Date
- Apr 28, 2024, 22:30 UTC
- Message-ID
- <4e93509c80f944b2d10c6d62853cecb78aa6a464.1714343461.git.gitgitgadget@gmail.com>
- In-Reply-To
- <pull.1715.git.git.1714343461.gitgitgadget@gmail.com>
From: Matheus Afonso Martins Moreira <matheus@matheusmoreira.com>
Parse the specified git URL component from each of the given git URLs and print them to standard output, one per line.
Signed-off-by: Matheus Afonso Martins Moreira <matheus@matheusmoreira.com> --- builtin/url-parse.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
diff --git a/builtin/url-parse.c b/builtin/url-parse.c index ab996eadf38..6c1a8676bad 100644 --- a/builtin/url-parse.c +++ b/builtin/url-parse.c @@ -102,6 +102,8 @@ static char *extract(enum url_component component, struct url_info *info) int cmd_url_parse(int argc, const char **argv, const char *prefix) { struct url_info info; + enum url_component selected = URL_NONE; + char *extracted; int i; argc = parse_options(argc, argv, prefix, @@ -109,8 +111,20 @@ int cmd_url_parse(int argc, const char **argv, const char *prefix) builtin_url_parse_usage, 0); + if (component_arg) + selected = get_component_or_die(component_arg); + for (i = 0; i < argc; ++i) { parse_or_die(argv[i], &info); + + if (selected != URL_NONE) { + extracted = extract(selected, &info); + if (extracted) { + puts(extracted); + free(extracted); + } + } + free(info.url); }
-- gitgitgadget