]> git.ipfire.org Git - thirdparty/git.git/commitdiff
promisor-remote: use string constants for 'name' and 'url' too
authorChristian Couder <christian.couder@gmail.com>
Wed, 11 Jun 2025 13:45:06 +0000 (15:45 +0200)
committerJunio C Hamano <gitster@pobox.com>
Thu, 12 Jun 2025 15:07:43 +0000 (08:07 -0700)
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.

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

index 939cc78a7da61cd94ca2f693ea8eb7842a461c86..07fa0158ec5f6ee518ea5b048f0fe576f10608b5 100644 (file)
@@ -314,6 +314,12 @@ static int allow_unsanitized(char ch)
        return ch > 32 && ch < 127;
 }
 
+/*
+ * All the fields used in "promisor-remote" protocol capability,
+ * including the mandatory "name" and "url" ones.
+ */
+static const char promisor_field_name[] = "name";
+static const char promisor_field_url[] = "url";
 static const char promisor_field_filter[] = "partialCloneFilter";
 static const char promisor_field_token[] = "token";
 
@@ -514,9 +520,9 @@ char *promisor_remote_info(struct repository *repo)
                if (item != config_info.items)
                        strbuf_addch(&sb, ';');
 
-               strbuf_addstr(&sb, "name=");
+               strbuf_addf(&sb, "%s=", promisor_field_name);
                strbuf_addstr_urlencode(&sb, p->name, allow_unsanitized);
-               strbuf_addstr(&sb, ",url=");
+               strbuf_addf(&sb, ",%s=", promisor_field_url);
                strbuf_addstr_urlencode(&sb, p->url, allow_unsanitized);
 
                if (p->filter) {
@@ -661,9 +667,9 @@ static struct promisor_info *parse_one_advertised_remote(struct strbuf *remote_i
                *p = '\0';
                value = url_percent_decode(p + 1);
 
-               if (!strcmp(elem, "name"))
+               if (!strcmp(elem, promisor_field_name))
                        info->name = value;
-               else if (!strcmp(elem, "url"))
+               else if (!strcmp(elem, promisor_field_url))
                        info->url = value;
                else if (!strcasecmp(elem, promisor_field_filter))
                        info->filter = value;