[PATCH 11/24] bundle-uri: create "key=value" line parsing
From: Ævar Arnfjörð Bjarmason via GitGitGadget <hidden>
Date: 2022-05-20 18:41:57
Subsystem:
the rest · Maintainer:
Linus Torvalds
From: =?UTF-8?q?=C3=86var=20Arnfj=C3=B6r=C3=B0=20Bjarmason?= [off-list ref] When advertising a bundle list over Git's protocol v2, we will use packet lines. Each line will be of the form "key=value" representing a bundle list. Connect the API necessary for Git's transport to the key-value pair parsing created in the previous change. Co-authored-by: Derrick Stolee [off-list ref] Signed-off-by: Ævar Arnfjörð Bjarmason <redacted> Signed-off-by: Derrick Stolee <redacted> --- bundle-uri.c | 29 +++++++++++++++++++++++++++-- bundle-uri.h | 14 +++++++++++++- 2 files changed, 40 insertions(+), 3 deletions(-)
diff --git a/bundle-uri.c b/bundle-uri.c
index f18bba7071d..948f974c478 100644
--- a/bundle-uri.c
+++ b/bundle-uri.c@@ -72,7 +72,6 @@ int for_all_bundles_in_list(struct bundle_list *list, * Returns 0 if the key-value pair is understood. Returns 1 if the key * is not understood or the value is malformed. */ -MAYBE_UNUSED static int bundle_list_update(const char *key, const char *value, struct bundle_list *list) {
@@ -300,4 +299,30 @@ cleanup: unlink(filename.buf); strbuf_release(&filename); return result; -}
\ No newline at end of file
+}
+
+/**
+ * General API for {transport,connect}.c etc.
+ */
+int bundle_uri_parse_line(struct bundle_list *list, const char *line)
+{
+ int result;
+ const char *equals;
+ struct strbuf key = STRBUF_INIT;
+
+ if (!strlen(line))
+ return error(_("bundle-uri: got an empty line"));
+
+ equals = strchr(line, '=');
+
+ if (!equals)
+ return error(_("bundle-uri: line is not of the form 'key=value'"));
+ if (line == equals || !*(equals + 1))
+ return error(_("bundle-uri: line has empty key or value"));
+
+ strbuf_add(&key, line, equals - line);
+ result = bundle_list_update(key.buf, equals + 1, list);
+ strbuf_release(&key);
+
+ return result;
+}diff --git a/bundle-uri.h b/bundle-uri.h
index 0f95197744c..344d5943922 100644
--- a/bundle-uri.h
+++ b/bundle-uri.h@@ -78,4 +78,16 @@ int for_all_bundles_in_list(struct bundle_list *list, */ int fetch_bundle_uri(struct repository *r, const char *uri); -#endif +/** + * General API for {transport,connect}.c etc. + */ + +/** + * Parse a "key=value" packet line from the bundle-uri verb. + * + * Returns 0 on success and non-zero on error. + */ +int bundle_uri_parse_line(struct bundle_list *list, + const char *line); + +#endif /* BUNDLE_URI_H */
--
gitgitgadget