Subject: [PATCH 04/13] url-parse: add URL parsing helper function

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

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

This function either successfully parses an URL
or dies with an error message. Since this is a
plumbing command, the error message is not translated.

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

diff --git a/builtin/url-parse.c b/builtin/url-parse.c
index 994ccec4b2e..933e63aaa0a 100644
--- a/builtin/url-parse.c
+++ b/builtin/url-parse.c
@@ -11,6 +11,16 @@
 
 #include "builtin.h"
 #include "gettext.h"
+#include "urlmatch.h"
+
+static void parse_or_die(const char *url, struct url_info *info)
+{
+	if (url_parse(url, info)) {
+		return;
+	} else {
+		die("invalid git URL '%s', %s", url, info->err);
+	}
+}
 
 int cmd_url_parse(int argc, const char **argv, const char *prefix)
 {
-- 
gitgitgadget