Git fork

promisor-remote: use string constants for 'name' and 'url' too

A previous commit started to define `promisor_field_filter` and
`promisor_field_token`, and used them instead of the
"partialCloneFilter" and "token" string literals.

Let's do the same for "name" and "url" to avoid repeating them
several times and for consistency with the other fields.

For skipping "name=" or "url=" in advertisements, let's introduce
a skip_field_name_prefix() helper function to keep parsing clean
and easy to understand.

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

authored by

Christian Couder and committed by
Junio C Hamano
4e2139c9 4bf7ae31

+19 -4
+19 -4
promisor-remote.c
··· 314 314 return ch > 32 && ch < 127; 315 315 } 316 316 317 + /* 318 + * All the fields used in "promisor-remote" protocol capability, 319 + * including the mandatory "name" and "url" ones. 320 + */ 321 + static const char promisor_field_name[] = "name"; 322 + static const char promisor_field_url[] = "url"; 317 323 static const char promisor_field_filter[] = "partialCloneFilter"; 318 324 static const char promisor_field_token[] = "token"; 319 325 ··· 497 503 if (item != config_info.items) 498 504 strbuf_addch(&sb, ';'); 499 505 500 - strbuf_addstr(&sb, "name="); 506 + strbuf_addf(&sb, "%s=", promisor_field_name); 501 507 strbuf_addstr_urlencode(&sb, p->name, allow_unsanitized); 502 - strbuf_addstr(&sb, ",url="); 508 + strbuf_addf(&sb, ",%s=", promisor_field_url); 503 509 strbuf_addstr_urlencode(&sb, p->url, allow_unsanitized); 504 510 505 511 if (p->filter) { ··· 563 569 return 0; 564 570 } 565 571 572 + static int skip_field_name_prefix(const char *elem, const char *field_name, const char **value) 573 + { 574 + const char *p; 575 + if (!skip_prefix(elem, field_name, &p) || *p != '=') 576 + return 0; 577 + *value = p + 1; 578 + return 1; 579 + } 580 + 566 581 static void filter_promisor_remote(struct repository *repo, 567 582 struct strvec *accepted, 568 583 const char *info) ··· 610 625 611 626 for (size_t j = 0; elems[j]; j++) { 612 627 strbuf_strip_suffix(elems[j], ","); 613 - if (!skip_prefix(elems[j]->buf, "name=", &remote_name)) 614 - skip_prefix(elems[j]->buf, "url=", &remote_url); 628 + if (!skip_field_name_prefix(elems[j]->buf, promisor_field_name, &remote_name)) 629 + skip_field_name_prefix(elems[j]->buf, promisor_field_url, &remote_url); 615 630 } 616 631 617 632 if (remote_name)