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>
Christian Couder committed
Sep 8, 2025 at 07:30 UTC
4e2139c9c52766f2853dd42c7ff76eee5ac86449
1 file changed
+19
-4
promisor-remote.c
+19
-4
@@ -314,6 +314,12 @@ static int allow_unsanitized(char ch)
314
return ch > 32 && ch < 127;
315
}
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";
323
static const char promisor_field_filter[] = "partialCloneFilter";
324
static const char promisor_field_token[] = "token";
325
@@ -497,9 +503,9 @@ char *promisor_remote_info(struct repository *repo)
503
if (item != config_info.items)
504
strbuf_addch(&sb, ';');
505
500
- strbuf_addstr(&sb, "name=");
506
+ strbuf_addf(&sb, "%s=", promisor_field_name);
507
strbuf_addstr_urlencode(&sb, p->name, allow_unsanitized);
502
- strbuf_addstr(&sb, ",url=");
508
+ strbuf_addf(&sb, ",%s=", promisor_field_url);
509
strbuf_addstr_urlencode(&sb, p->url, allow_unsanitized);
510
511
if (p->filter) {
@@ -563,6 +569,15 @@ static int should_accept_remote(enum accept_promisor accept,
569
return 0;
570
}
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
+
581
static void filter_promisor_remote(struct repository *repo,
582
struct strvec *accepted,
583
const char *info)
@@ -610,8 +625,8 @@ static void filter_promisor_remote(struct repository *repo,
625
626
for (size_t j = 0; elems[j]; j++) {
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);
630
}
631
632
if (remote_name)