Skip to content

Commit 4e2139c

Browse files
chriscoolgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 4bf7ae3 commit 4e2139c

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

promisor-remote.c

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,12 @@ static int allow_unsanitized(char ch)
314314
return ch > 32 && ch < 127;
315315
}
316316

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";
317323
static const char promisor_field_filter[] = "partialCloneFilter";
318324
static const char promisor_field_token[] = "token";
319325

@@ -497,9 +503,9 @@ char *promisor_remote_info(struct repository *repo)
497503
if (item != config_info.items)
498504
strbuf_addch(&sb, ';');
499505

500-
strbuf_addstr(&sb, "name=");
506+
strbuf_addf(&sb, "%s=", promisor_field_name);
501507
strbuf_addstr_urlencode(&sb, p->name, allow_unsanitized);
502-
strbuf_addstr(&sb, ",url=");
508+
strbuf_addf(&sb, ",%s=", promisor_field_url);
503509
strbuf_addstr_urlencode(&sb, p->url, allow_unsanitized);
504510

505511
if (p->filter) {
@@ -563,6 +569,15 @@ static int should_accept_remote(enum accept_promisor accept,
563569
return 0;
564570
}
565571

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+
566581
static void filter_promisor_remote(struct repository *repo,
567582
struct strvec *accepted,
568583
const char *info)
@@ -610,8 +625,8 @@ static void filter_promisor_remote(struct repository *repo,
610625

611626
for (size_t j = 0; elems[j]; j++) {
612627
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);
615630
}
616631

617632
if (remote_name)

0 commit comments

Comments
 (0)