diff options
author | Ævar Arnfjörð Bjarmason <avarab@gmail.com> | 2022-10-12 15:52:31 +0300 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2022-10-12 19:13:24 +0300 |
commit | 9424e373fd2136aa7f5cec23c8cafc272996ecd6 (patch) | |
tree | 85ca81d76f54a749060acad6c4de0564213a2cf8 /bundle-uri.c | |
parent | bff03c47f7342c2a08fac6c0af7229b1579fea15 (diff) |
bundle-uri: create "key=value" line parsing
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.
We are not currently implementing this protocol v2 functionality, but
instead preparing to expose this parsing to be unit-testable.
Co-authored-by: Derrick Stolee <derrickstolee@github.com>
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Derrick Stolee <derrickstolee@github.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'bundle-uri.c')
-rw-r--r-- | bundle-uri.c | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/bundle-uri.c b/bundle-uri.c index 0bc59dd9c3..372e6fac5c 100644 --- a/bundle-uri.c +++ b/bundle-uri.c @@ -71,7 +71,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) { @@ -306,3 +305,29 @@ cleanup: free(filename); return result; } + +/** + * 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; +} |