Skip to content

Commit 9424e37

Browse files
avarderrickstolee
authored andcommitted
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 <[email protected]> Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Derrick Stolee <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent bff03c4 commit 9424e37

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

bundle-uri.c

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ int for_all_bundles_in_list(struct bundle_list *list,
7171
* Returns 0 if the key-value pair is understood. Returns -1 if the key
7272
* is not understood or the value is malformed.
7373
*/
74-
MAYBE_UNUSED
7574
static int bundle_list_update(const char *key, const char *value,
7675
struct bundle_list *list)
7776
{
@@ -306,3 +305,29 @@ int fetch_bundle_uri(struct repository *r, const char *uri)
306305
free(filename);
307306
return result;
308307
}
308+
309+
/**
310+
* General API for {transport,connect}.c etc.
311+
*/
312+
int bundle_uri_parse_line(struct bundle_list *list, const char *line)
313+
{
314+
int result;
315+
const char *equals;
316+
struct strbuf key = STRBUF_INIT;
317+
318+
if (!strlen(line))
319+
return error(_("bundle-uri: got an empty line"));
320+
321+
equals = strchr(line, '=');
322+
323+
if (!equals)
324+
return error(_("bundle-uri: line is not of the form 'key=value'"));
325+
if (line == equals || !*(equals + 1))
326+
return error(_("bundle-uri: line has empty key or value"));
327+
328+
strbuf_add(&key, line, equals - line);
329+
result = bundle_list_update(key.buf, equals + 1, list);
330+
strbuf_release(&key);
331+
332+
return result;
333+
}

bundle-uri.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,16 @@ int for_all_bundles_in_list(struct bundle_list *list,
6767
*/
6868
int fetch_bundle_uri(struct repository *r, const char *uri);
6969

70+
/**
71+
* General API for {transport,connect}.c etc.
72+
*/
73+
74+
/**
75+
* Parse a "key=value" packet line from the bundle-uri verb.
76+
*
77+
* Returns 0 on success and non-zero on error.
78+
*/
79+
int bundle_uri_parse_line(struct bundle_list *list,
80+
const char *line);
81+
7082
#endif

0 commit comments

Comments
 (0)