From patchwork Mon Apr 14 16:03:40 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Couder X-Patchwork-Id: 14050666 Received: from mail-wr1-f44.google.com (mail-wr1-f44.google.com [209.85.221.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F410319F130 for ; Mon, 14 Apr 2025 16:04:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744646656; cv=none; b=nEZuz8ZyRleE1ltepEMK8ml+w6LZfM6yky1jDDn71xzNspNwSUZ3URBW0fTFvsn6HU9tjL3HtD8NhWZp/abz7ll4SR6t2NCsTyjmLPjAfsm7OXJKzHYcKfkeH052m2wG+Q0V62PoUxJ0U1LObN7zJt8vppqAMkftepIeWGgAOY8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744646656; c=relaxed/simple; bh=cJki+j/PM6d0h/t6RqZdzvZ7IFfQm56URuQ75LPsIP0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TVdjsETb355lfLuMnsUvSn47nli/uLW1csOOqcEMNEekoMf5WB51ZLGhDMObjDF2pc7hYQDSwU0VKg3zh5JQxStOAOBUPWChrOUTZo74Fb06W7V/3bGsbZYVmvna94CkZukD/RoiVohQxAX4ClmahqwSs8ncG2+/D34aqE2yL9I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=gYzjy64M; arc=none smtp.client-ip=209.85.221.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="gYzjy64M" Received: by mail-wr1-f44.google.com with SMTP id ffacd0b85a97d-399737f4fa4so2615773f8f.0 for ; Mon, 14 Apr 2025 09:04:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1744646653; x=1745251453; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=bY2/TrYxCDoPnvu+GiF+SznZ3h0aSdSueR8XVgFz3KU=; b=gYzjy64MOfRzH/X6fRoDrOc6dtbvY/yxSvSGCIFecOdDQMV093RqDxoKfkITAHBOS9 BSKMpF24jVT2OrRWAwOGhToIRPIbBtFALqksTkKgW0v3cnIJyWmIQA0IwNScpjDBsSB4 h+uSV2o1N3NEAP2i2px1fk+hLh2VqWazCZ7CwVAr/+hkGMLXA5Gmn48b888iLq+abhKN wiKAAv15coKx12CCfWX3mNAzWAUzeVjay+IFsYXq6S/KCHdxWMoHTNcBv2+I8JxWxlvE GFXurqAM+r3AFezTUXavdFhRU2+yP2ItIBIux1lExu1p1JRx/pqgv/k5p2EgJD+h/uVf oRQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744646653; x=1745251453; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=bY2/TrYxCDoPnvu+GiF+SznZ3h0aSdSueR8XVgFz3KU=; b=bYzyWjGPZrGmF4076PvjNz8x2XSPCvg0j0WS4GHu6C0TyuCgKC63fOwdbGQncrRRtd 28W7RlI+D+i/t1jeEncsCeAjX0WA9xQcvP/VwGqS40r3NsqnntHDIsLfLo9FajOxpJRW k7gXmZAbnAMBzZEbymiX7fbMZm2Q518VO6K4Jjzw36SPuPCac9wwawbsqiscXL2hgDw0 lxgYhDhncsjRo3o5zSMB/KnU2ZQ4OirVvCPdMRzsC5XTBBHKMKs91rUUWGeegQUbh/DU xJ8rQG1tpdtuEzvHLVbic/9V3jxHUMOVPT6ms64dCJm3WotFk4VnVKTnkEXrnQ+77HIG 3ecQ== X-Gm-Message-State: AOJu0YwpWskqlRBN63gEwA9xYzB/1U4lWAkaJaDR5SXzEUjo1z/R1DUD el+bQ3Z1jVzhKryMk/htHhbiey0mHGpahHeHpQ0r0HOht5yWkH3VmUWSlg== X-Gm-Gg: ASbGncvBVEIgAbLcU77dgMpYjpemppjohYcfDKnkExqtQtqshG0eEcb+K/Gc6R09PxQ SVoXXGdgUOxAOFJRa5LLb6khfF9DDzYi9vP4fmIfbJvajoongCnf+HtPNBEyO635NhW1Jy3SBJS Ohj8eP6ka8Wo1AoSGA4TRm38nSEjLgAX9HtxShV7C54XCYlXbE/5Q9eUtYW1pFh1j/kSJzH1yUP SWzee9xnyi8G1zE+ThXMYEiPi/DIzAi8q0yx5ySKZmnIjsMTZ3KMrjo0Wpn8K+xUuexJx0Z4NMU VzAVjEh68cGMrsWhXF86wLNOOuAeSN+eOgoqUbpiP02Uwqut3NuVQKRWSaKfnrKz8j0MutqgaDc = X-Google-Smtp-Source: AGHT+IEUBzSyv7IFjEpyl6ls/S4RJ7hIBzRR78cZiasQxU9CTSkH5Q4l78hIWn02XVQrqL6aw8Pdgg== X-Received: by 2002:a05:6000:1788:b0:39c:12ce:6a0 with SMTP id ffacd0b85a97d-39ea520373amr10470188f8f.21.1744646650610; Mon, 14 Apr 2025 09:04:10 -0700 (PDT) Received: from christian-Precision-5550.lan ([2001:861:3f04:7ca0:a9d4:af7b:bb5c:77e4]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-39eae977513sm11258029f8f.42.2025.04.14.09.04.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Apr 2025 09:04:09 -0700 (PDT) From: Christian Couder To: git@vger.kernel.org Cc: Junio C Hamano , Patrick Steinhardt , Taylor Blau , Karthik Nayak , Christian Couder , Christian Couder Subject: [PATCH 1/4] config: move is_config_key_char() to "config.h" Date: Mon, 14 Apr 2025 18:03:40 +0200 Message-ID: <20250414160343.2216312-2-christian.couder@gmail.com> X-Mailer: git-send-email 2.49.0.158.gd3b09c1afe In-Reply-To: <20250414160343.2216312-1-christian.couder@gmail.com> References: <20250414160343.2216312-1-christian.couder@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The iskeychar() function in "config.c" checks if a character is valid for the section or variable name part of a config key. In a follow up commit we will want to check outside "config.c" if a string can be a valid variable name of a config key, so will will want to reuse that fonction. Let's then move it from "config.c" to "config.h", and, while at it, let's rename it to is_config_key_char(). Signed-off-by: Christian Couder --- config.c | 11 +++-------- config.h | 9 +++++++++ 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/config.c b/config.c index e127afaa8f..f529cb4cbe 100644 --- a/config.c +++ b/config.c @@ -531,11 +531,6 @@ void git_config_push_env(const char *spec) free(key); } -static inline int iskeychar(int c) -{ - return isalnum(c) || c == '-'; -} - /* * Auxiliary function to sanity-check and split the key into the section * identifier and variable name. @@ -585,7 +580,7 @@ int git_config_parse_key(const char *key, char **store_key, size_t *baselen_) dot = 1; /* Leave the extended basename untouched.. */ if (!dot || i > baselen) { - if (!iskeychar(c) || + if (!is_config_key_char(c) || (i == baselen + 1 && !isalpha(c))) { error(_("invalid key: %s"), key); goto out_free_ret_1; @@ -906,7 +901,7 @@ static int get_value(struct config_source *cs, struct key_value_info *kvi, c = get_next_char(cs); if (cs->eof) break; - if (!iskeychar(c)) + if (!is_config_key_char(c)) break; strbuf_addch(name, tolower(c)); } @@ -984,7 +979,7 @@ static int get_base_var(struct config_source *cs, struct strbuf *name) return 0; if (isspace(c)) return get_extended_base_var(cs, name, c); - if (!iskeychar(c) && c != '.') + if (!is_config_key_char(c) && c != '.') return -1; strbuf_addch(name, tolower(c)); } diff --git a/config.h b/config.h index 29a0277483..16df47f446 100644 --- a/config.h +++ b/config.h @@ -340,6 +340,15 @@ int repo_config_set_worktree_gently(struct repository *, const char *, const cha */ void repo_config_set(struct repository *, const char *, const char *); +/** + * Is this char a valid char for the section or variable name part of + * a config key? + */ +static inline int is_config_key_char(int c) +{ + return isalnum(c) || c == '-'; +} + int git_config_parse_key(const char *, char **, size_t *); /* From patchwork Mon Apr 14 16:03:41 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Couder X-Patchwork-Id: 14050667 Received: from mail-wr1-f53.google.com (mail-wr1-f53.google.com [209.85.221.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E9B6B27B512 for ; Mon, 14 Apr 2025 16:04:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744646657; cv=none; b=QHCiOywBbBxfCe1IoawNR2G/ejwP/6B1DNH3M7rM8Ea71Hp8KN5KA0jNQhw3HhHh9zGpi4t386gQ4Y7ScFlf/YcsVC2/BxM3skcWWhwDO2qP8cHzm29pmQB4/FTJnJyP2kaa0qCABDgy7ZklcczCqLYVbvQEf+kaN3CZj5QPAUk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744646657; c=relaxed/simple; bh=pbwm2Q8Xcta2B4AdmnaegU6rhLs9UiHgFsLz5a221NM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nmfhL3SeAzBpPO7bLiPsLFcIEqqmp+LUZhw6AMvIw2i4Ko2ddD1Ty028MtgCmlBMhGli05T20/tAn1R6zHSUddSfQR3uTTtkjndel34LVt34CmtiWgPOQBj8RXmcBeJLQWlh+TmscfIcT4U4rywl3sdQyIOh8Nwvs5WczPv9DCQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=kqlQQfLV; arc=none smtp.client-ip=209.85.221.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="kqlQQfLV" Received: by mail-wr1-f53.google.com with SMTP id ffacd0b85a97d-3913b539aabso2707253f8f.2 for ; Mon, 14 Apr 2025 09:04:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1744646653; x=1745251453; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=pgajhPRf+bdlOs5P1RR2J7u1G+Sh8ym6z97HpQfX4Eo=; b=kqlQQfLVVNBvlAyk4GGahB9nkc+Xdhykte83m32PHQpR8PSzlcybjH2HUmcy2JtJIo rPQa+aFmK8Tytkz1LSISUSAA6SBKvUXGgBFYz23qJ0EPcy1sJbI/lr3JdHRHWICF4b8t JwE0GvYIt7EGSIHkyMwBhQNe90kKg/V3cwcIDg7gq+ZCALfw/pqZvUEXK+wySb0ycwLb flau9OSiN58Xz+jF1un3Ipe2mUcYQZtpoexrDH9pywQaw3KV7dXxw+m7ZAiOCqX1J8S1 xlpU9Y3/LaaOxI+1/2rzAOlHBGFk9hpx1mhhcgwxCC2KfRh6kY+CVWDV8ADjFv09riaZ DYwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744646653; x=1745251453; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=pgajhPRf+bdlOs5P1RR2J7u1G+Sh8ym6z97HpQfX4Eo=; b=nh3zgeDv3bugbdYpXW7ibJL7/c9x5j/ZVcM2H2ojo1Bonu7H/xT6/s2gZNATHXRZRH uVbLpdCamuOhUcwk6665wP4XbkD+wok4f8ujwnGaH6hgSdk1hhsO7iW475pUhgEX/xLT dhEcSBHSXgdesyoS4kiWtu/r++a0KcfODZZx8TCpD7o1uoY7cgtcQAr2s33cxbfWBjbR eUmaNPJnXbfpfucKSMoQU4V0aYm71VuFhUMsZfKdG02ltWTAMN+glcvNANOc3otszYT+ URti0DQko+zylvXwDAWQ2NdI7Wb69ovOqNjZ503DnNeiLaB/vnPLI5bairBO5Nmbz80T ppaQ== X-Gm-Message-State: AOJu0YwVxkYQk+TR5LpaFKVCNY9jb+WWFBRJahacWD6O4VJuY/g5hhxo p1t4qhjUBSH4RUuIiYQpSlQEvM/SNJo/tJv1+mieEHqXsgUs5kpTNUjQuQ== X-Gm-Gg: ASbGncs7p/untz1QFJG+vpfvtMJpIfnzInomRdDSPq2bSxbyY91i554zEyvYQZvRiT+ Gt+voRL3x1Fziq44PwTDhDict0ICyDKYQ58IfX+ItdrZFzMHOV+5Rfhi6SLlm2LzKn9ivQhfjST GNRmkemPvQ1SVEfGd3Xttibt9vmg/27X3lPqolfL5CDROTIjkA4xFNHz22if2XN+CCF1geDT3T4 NT0qgMb/yZIC6vpFMSnYmtMw5qSAv1CHGd2Jh/aPdreAM8z2TUEOV9NVlA4VkkCeZ9diZ46Jryt CVU/xh2iCeVKYJNuQT+8BOyBIxjULZ5IlOctwygXcJIHW13ZPR60CLLEyuCQjCvGk8MuFMRDN/4 = X-Google-Smtp-Source: AGHT+IHjMsPBWrad7kPPEzOBqhzUJhWKZZQ8aVcRcsLd8/VSkIjtJgEC5AEz5b7f0snrculUnmGbZg== X-Received: by 2002:a5d:64e7:0:b0:391:2ab1:d4b8 with SMTP id ffacd0b85a97d-39ea51d353dmr10527590f8f.1.1744646652296; Mon, 14 Apr 2025 09:04:12 -0700 (PDT) Received: from christian-Precision-5550.lan ([2001:861:3f04:7ca0:a9d4:af7b:bb5c:77e4]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-39eae977513sm11258029f8f.42.2025.04.14.09.04.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Apr 2025 09:04:10 -0700 (PDT) From: Christian Couder To: git@vger.kernel.org Cc: Junio C Hamano , Patrick Steinhardt , Taylor Blau , Karthik Nayak , Christian Couder , Christian Couder Subject: [PATCH 2/4] promisor-remote: refactor to get rid of 'struct strvec' Date: Mon, 14 Apr 2025 18:03:41 +0200 Message-ID: <20250414160343.2216312-3-christian.couder@gmail.com> X-Mailer: git-send-email 2.49.0.158.gd3b09c1afe In-Reply-To: <20250414160343.2216312-1-christian.couder@gmail.com> References: <20250414160343.2216312-1-christian.couder@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 In a following commit, we will use the new 'promisor-remote' protocol capability introduced by d460267613 (Add 'promisor-remote' capability to protocol v2, 2025-02-18) to pass and process more information about promisor remotes than just their name and url. For that purpose, we will need to store information about other fields, especially information that might or might not be available for different promisor remotes. Unfortunately using 'struct strvec', as we currently do, to store information about the promisor remotes with one 'struct strvec' for each field like "name" or "url" does not scale easily in that case. Let's refactor this and introduce a new 'struct promisor_info' linked list that contains a 'struct string_list fields'. This string_list stores the field names, like "name" and "url", in the 'string' member of its items, and the field values in the 'util' member of its items. Signed-off-by: Christian Couder --- promisor-remote.c | 124 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 87 insertions(+), 37 deletions(-) diff --git a/promisor-remote.c b/promisor-remote.c index 5801ebfd9b..0fb07f25af 100644 --- a/promisor-remote.c +++ b/promisor-remote.c @@ -314,10 +314,38 @@ static int allow_unsanitized(char ch) return ch > 32 && ch < 127; } -static void promisor_info_vecs(struct repository *repo, - struct strvec *names, - struct strvec *urls) +/* + * Linked list for promisor remotes. + * + * 'fields' should not be sorted, as we will rely on the order we put + * things into it. So, for example, 'string_list_append()' should be + * used instead of 'string_list_insert()'. + */ +struct promisor_info { + struct promisor_info *next; + struct string_list fields; +}; + +static void free_info_list(struct promisor_info *p) +{ + struct promisor_info *next; + + for (; p; p = next) { + next = p->next; + string_list_clear(&p->fields, 0); + free(p); + } +} + +/* + * Prepare a 'struct promisor_info' linked list of promisor + * remotes. For each promisor remote, some of its fields, starting + * with "name" and "url", are put in the 'fields' string_list. + */ +static struct promisor_info *promisor_info_list(struct repository *repo) { + struct promisor_info *infos = NULL; + struct promisor_info **last_info = &infos; struct promisor_remote *r; promisor_remote_init(repo); @@ -328,57 +356,75 @@ static void promisor_info_vecs(struct repository *repo, /* Only add remotes with a non empty URL */ if (!git_config_get_string_tmp(url_key, &url) && *url) { - strvec_push(names, r->name); - strvec_push(urls, url); + struct promisor_info *new_info = xcalloc(1, sizeof(*new_info)); + + string_list_init_dup(&new_info->fields); + + string_list_append(&new_info->fields, "name")->util = (char *)r->name; + string_list_append(&new_info->fields, "url")->util = (char *)url; + + *last_info = new_info; + last_info = &new_info->next; } free(url_key); } + + return infos; } char *promisor_remote_info(struct repository *repo) { struct strbuf sb = STRBUF_INIT; int advertise_promisors = 0; - struct strvec names = STRVEC_INIT; - struct strvec urls = STRVEC_INIT; + struct promisor_info *info_list; + struct promisor_info *r, *p; git_config_get_bool("promisor.advertise", &advertise_promisors); if (!advertise_promisors) return NULL; - promisor_info_vecs(repo, &names, &urls); + info_list = promisor_info_list(repo); - if (!names.nr) + if (!info_list) return NULL; - for (size_t i = 0; i < names.nr; i++) { - if (i) + for (p = NULL, r = info_list; r; p = r, r = r->next) { + struct string_list_item *item; + int first = 1; + + if (r != info_list) strbuf_addch(&sb, ';'); - strbuf_addstr(&sb, "name="); - strbuf_addstr_urlencode(&sb, names.v[i], allow_unsanitized); - strbuf_addstr(&sb, ",url="); - strbuf_addstr_urlencode(&sb, urls.v[i], allow_unsanitized); + + for_each_string_list_item(item, &r->fields) { + if (first) + first = 0; + else + strbuf_addch(&sb, ','); + strbuf_addf(&sb, "%s=", item->string); + strbuf_addstr_urlencode(&sb, (char *)item->util, allow_unsanitized); + } } - strvec_clear(&names); - strvec_clear(&urls); + free_info_list(p); return strbuf_detach(&sb, NULL); } /* - * Find first index of 'nicks' where there is 'nick'. 'nick' is - * compared case sensitively to the strings in 'nicks'. If not found - * 'nicks->nr' is returned. + * Find first element of 'p' where the 'name' field is 'nick'. 'nick' + * is compared case sensitively to the strings in 'p'. If not found + * NULL is returned. */ -static size_t remote_nick_find(struct strvec *nicks, const char *nick) +static struct promisor_info *remote_nick_find(struct promisor_info *p, const char *nick) { - for (size_t i = 0; i < nicks->nr; i++) - if (!strcmp(nicks->v[i], nick)) - return i; - return nicks->nr; + for (; p; p = p->next) { + assert(!strcmp(p->fields.items[0].string, "name")); + if (!strcmp(p->fields.items[0].util, nick)) + return p; + } + return NULL; } enum accept_promisor { @@ -390,16 +436,17 @@ enum accept_promisor { static int should_accept_remote(enum accept_promisor accept, const char *remote_name, const char *remote_url, - struct strvec *names, struct strvec *urls) + struct promisor_info *info_list) { - size_t i; + struct promisor_info *p; + const char *local_url; if (accept == ACCEPT_ALL) return 1; - i = remote_nick_find(names, remote_name); + p = remote_nick_find(info_list, remote_name); - if (i >= names->nr) + if (!p) /* We don't know about that remote */ return 0; @@ -414,11 +461,16 @@ static int should_accept_remote(enum accept_promisor accept, return 0; } - if (!strcmp(urls->v[i], remote_url)) + if (strcmp(p->fields.items[1].string, "url")) + BUG("Bad info_list for remote '%s'", remote_name); + + local_url = p->fields.items[1].util; + + if (!strcmp(local_url, remote_url)) return 1; warning(_("known remote named '%s' but with URL '%s' instead of '%s'"), - remote_name, urls->v[i], remote_url); + remote_name, local_url, remote_url); return 0; } @@ -430,8 +482,7 @@ static void filter_promisor_remote(struct repository *repo, struct strbuf **remotes; const char *accept_str; enum accept_promisor accept = ACCEPT_NONE; - struct strvec names = STRVEC_INIT; - struct strvec urls = STRVEC_INIT; + struct promisor_info *info_list = NULL; if (!git_config_get_string_tmp("promisor.acceptfromserver", &accept_str)) { if (!*accept_str || !strcasecmp("None", accept_str)) @@ -451,7 +502,7 @@ static void filter_promisor_remote(struct repository *repo, return; if (accept != ACCEPT_ALL) - promisor_info_vecs(repo, &names, &urls); + info_list = promisor_info_list(repo); /* Parse remote info received */ @@ -482,7 +533,7 @@ static void filter_promisor_remote(struct repository *repo, if (remote_url) decoded_url = url_percent_decode(remote_url); - if (decoded_name && should_accept_remote(accept, decoded_name, decoded_url, &names, &urls)) + if (decoded_name && should_accept_remote(accept, decoded_name, decoded_url, info_list)) strvec_push(accepted, decoded_name); strbuf_list_free(elems); @@ -490,8 +541,7 @@ static void filter_promisor_remote(struct repository *repo, free(decoded_url); } - strvec_clear(&names); - strvec_clear(&urls); + free_info_list(info_list); strbuf_list_free(remotes); } From patchwork Mon Apr 14 16:03:42 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Couder X-Patchwork-Id: 14050668 Received: from mail-wr1-f44.google.com (mail-wr1-f44.google.com [209.85.221.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5AEA927FD48 for ; Mon, 14 Apr 2025 16:04:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744646659; cv=none; b=P5V6ugQ9fodUbWS0iqPDDZ2T5UQX72e2iMzV9oO58TEc0ReVsynWCkgOF7KQvfZdXc8dOI+/U+TNXDJYph7DEauR/9SaDGDjgRp2pEmkje2C0Vwj2ZMj7N03EHns81Vds7ZW44cjSFUipAXA2nVl+n59Np7ra4rOxUT1MVgy3DY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744646659; c=relaxed/simple; bh=28QxZscrjCKLGNy42Vz0m47aYYkYxK/SWbZX5R4G+Gs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FQKgtYLJCERdi46Ebgkmc2v9dFadhvqP/lePEMJi+vHwgu15V/QMSTfBbTJKwVomRhe8OZH7aIkzaW3rHmrULBPrlljowMZQpNqLI6WW46JbTrMcv/0mf4GZwWDUK4y3SV73qZZW1Ap+Vq3W9hVqI99O0iS0JXVQsRgqHoSo3NA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=FPw27Iox; arc=none smtp.client-ip=209.85.221.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="FPw27Iox" Received: by mail-wr1-f44.google.com with SMTP id ffacd0b85a97d-3912d2c89ecso4239942f8f.2 for ; Mon, 14 Apr 2025 09:04:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1744646653; x=1745251453; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=TVpBcShTDNPOIYcIhwweVlGmsDpd6UOWlzB7PGNUNUI=; b=FPw27Iox7iJeG+Z1M16p06ZsUp7IDrAIOIPrilQjgm17zYa3Zb5iVPbX7wPjpis5ER VeDD/oUBnqUoxaB3diwGbwpDi6v/hlR8OOX9ZIn24AiXe/ydUBAjI/UuTNZOF2HujHBa GFxYYA20xmGptjA8bIW+KZMX15Zu8+FW3+1I7SZqr6VlvFWOuyBPxjB6oAeHdXHHp3HZ l4IS5t08oB+gxO/SIvvIlnISYhuSbDhrBS1DXCQ7erZ89aJhUC3wJg2K8tSj3qDeRMqf +RMGXtucUdd6mRU5Ufd9w50jB6cRV6AR+T3/CySqObis3yA49JYyz1dbg5kxwyIbmGfG igAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744646653; x=1745251453; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=TVpBcShTDNPOIYcIhwweVlGmsDpd6UOWlzB7PGNUNUI=; b=qC7fA6eRvrKCq1cQh0BoBk3CypA/xjqS0h5cYmpXvsaRVdMHrEG3jLXeDbhew7rxKZ 4Tsp8wXSgKfyx934hlEiCrSCL50mYpmbreIYXrN/g5oLFKvHSWiMKAF4715LuCZzz8BJ /sa34TPqi1tyS4Cayl7G5yKVcoT4vOU9meCVHBR1o2F+ngPFOhdSVBPT2pJoTuzPV5oP E1lZaB9EYF0vxmQqBlMmFkMQ5u8wNIdmXA/9PmrGptFCq6tBWzmeLlbyLzH0VA/eX11Q XUI9upuy/fLCyhq+4La6cM+jMrMAKeGI9IqvpGrCkZs4UYaVmg0LVzqBWGdmhsEIpnwq d2pQ== X-Gm-Message-State: AOJu0Yy+ZSDnrgnvHkpb6Zotag8yMibHvtP+EU0BnpWyt+6yMLYVwzBo dXe5eDy4DfdG2pbt3EWPFi3c/b7XdpthUS26/hjly2CIF5voNgqOJk/MFQ== X-Gm-Gg: ASbGncub5AS1kumSd8FrDzv/7U8hvJzZfV39y14dXhQC5Z+WWpx2dq2EKsNtmgmyMCv l5Te42BQR1YBbp8ZeF4LqtCI0N1clc/WXWlnPdQ9nhhEjL002UxsPzyBC8a8/EA6kuwMfzjDFGd ALH4Tyewhp/AKzHjYOjLjV3pYdwBZTuSJZXG7JeT8fWiBUaaJAT3nHeJGImPdfnsLfIiimmnxbs OGgE+QsIpaLjfELpTscSad4RPS+mGWVCjPxZglFlyOSV4F5IRtCNt7ds4sxn4nrfn5+H8fLWP4Q PqtBAhp50rlR9cjnuPZx+LXWPOruP48EnxKvVkHUanYuixTbX5nQHU3JKWjJn7s0BcAoeXndcxU = X-Google-Smtp-Source: AGHT+IGGJgWd7yoOLAbxotov0UQusyvKMjAd5vTQmAZr3LJXmRvsoSmU9GdEnD82Mq1euMmuM21zKg== X-Received: by 2002:a05:6000:4287:b0:39c:1257:cd41 with SMTP id ffacd0b85a97d-39eaaede3a4mr10404297f8f.59.1744646653075; Mon, 14 Apr 2025 09:04:13 -0700 (PDT) Received: from christian-Precision-5550.lan ([2001:861:3f04:7ca0:a9d4:af7b:bb5c:77e4]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-39eae977513sm11258029f8f.42.2025.04.14.09.04.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Apr 2025 09:04:12 -0700 (PDT) From: Christian Couder To: git@vger.kernel.org Cc: Junio C Hamano , Patrick Steinhardt , Taylor Blau , Karthik Nayak , Christian Couder , Christian Couder Subject: [PATCH 3/4] promisor-remote: allow a server to advertise extra fields Date: Mon, 14 Apr 2025 18:03:42 +0200 Message-ID: <20250414160343.2216312-4-christian.couder@gmail.com> X-Mailer: git-send-email 2.49.0.158.gd3b09c1afe In-Reply-To: <20250414160343.2216312-1-christian.couder@gmail.com> References: <20250414160343.2216312-1-christian.couder@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 For now the "promisor-remote" protocol capability can only pass "name" and "url" information from a server to a client in the form "name=,url=". Let's make it possible to pass more information by introducing a new "promisor.sendExtraFields" configuration variable. This variable should contain a comma or space separated list of fields that will be looked up in the configuration of the remote on the server to find the values that will be passed to the client. For example if "promisor.sendExtraFields" is set to "partialCloneFilter", and the server has the "remote..partialCloneFilter" config variable set to a value for a remote, then that value will be passed in the form "partialCloneFilter=" after the "name" and "url" fields. A following commit will allow the client to use the extra information to decide if it accepts the remote or not. For now the client doesn't do anything with the extra information it receives. Signed-off-by: Christian Couder --- Documentation/config/promisor.adoc | 15 ++++++ Documentation/gitprotocol-v2.adoc | 42 +++++++++------ promisor-remote.c | 75 ++++++++++++++++++++++++--- t/t5710-promisor-remote-capability.sh | 32 ++++++++++++ 4 files changed, 139 insertions(+), 25 deletions(-) diff --git a/Documentation/config/promisor.adoc b/Documentation/config/promisor.adoc index 2638b01f83..bc08999733 100644 --- a/Documentation/config/promisor.adoc +++ b/Documentation/config/promisor.adoc @@ -9,6 +9,21 @@ promisor.advertise:: "false", which means the "promisor-remote" capability is not advertised. +promisor.sendExtraFields:: + A comma or space separated list of additional remote related + fields that a server will send while advertising its promisor + remotes using the "promisor-remote" capability, see + linkgit:gitprotocol-v2[5]. When a field named "bar" is part of + this list and a corresponding "remote.foo.bar" config variable + is set on the server to a non empty value, for example "baz", + then the field and its value, so "bar=baz", will be sent when + advertising the promisor remote "foo". This list has no effect + unless the "promisor.advertise" config variable, see above, is + set to "true", and if that's the case, then whatever this list + contains, the "name" and "url" fields are advertised anyway + and contain the remote name and URL respectively, so there is + no need to add "name" or "url" to this list. + promisor.acceptFromServer:: If set to "all", a client will accept all the promisor remotes a server might advertise using the "promisor-remote" diff --git a/Documentation/gitprotocol-v2.adoc b/Documentation/gitprotocol-v2.adoc index 5598c93e67..f649745837 100644 --- a/Documentation/gitprotocol-v2.adoc +++ b/Documentation/gitprotocol-v2.adoc @@ -785,33 +785,39 @@ retrieving the header from a bundle at the indicated URI, and thus save themselves and the server(s) the request(s) needed to inspect the headers of that bundle or bundles. -promisor-remote= +promisor-remote= ~~~~~~~~~~~~~~~~~~~~~~~~~~ The server may advertise some promisor remotes it is using or knows about to a client which may want to use them as its promisor remotes, -instead of this repository. In this case should be of the +instead of this repository. In this case should be of the form: - pr-infos = pr-info | pr-infos ";" pr-info + pr-info = pr-fields | pr-info ";" pr-info - pr-info = "name=" pr-name | "name=" pr-name "," "url=" pr-url + pr-fields = fld-key "=" fld-value | pr-fields "," pr-fields -where `pr-name` is the urlencoded name of a promisor remote, and -`pr-url` the urlencoded URL of that promisor remote. +where all the `fld-key` and `fld-value` in a given `pr-fields` are +field keys and values related to a single promisor remote. -In this case, if the client decides to use one or more promisor -remotes the server advertised, it can reply with -"promisor-remote=" where should be of the form: +The server MUST advertise at least the "name" and "url" field keys +along with the associated field values, which are the name of a valid +remote and its URL, in each `pr-fields`. - pr-names = pr-name | pr-names ";" pr-name +`fld-key` MUST start with an alphabetic character and contain only +alphanumeric or '-' characters, and `fld-value` MUST be urlencoded. + +If the client decides to use one or more promisor remotes the server +advertised, it can reply with "promisor-remote=" where + should be of the form: + + pr-names = pr-name | pr-names ";" pr-names where `pr-name` is the urlencoded name of a promisor remote the server advertised and the client accepts. -Note that, everywhere in this document, `pr-name` MUST be a valid -remote name, and the ';' and ',' characters MUST be encoded if they -appear in `pr-name` or `pr-url`. +Note that, everywhere in this document, the ';' and ',' characters +MUST be encoded if they appear in `pr-name` or `fld-value`. If the server doesn't know any promisor remote that could be good for a client to use, or prefers a client not to use any promisor remote it @@ -822,10 +828,12 @@ In this case, or if the client doesn't want to use any promisor remote the server advertised, the client shouldn't advertise the "promisor-remote" capability at all in its reply. -The "promisor.advertise" and "promisor.acceptFromServer" configuration -options can be used on the server and client side to control what they -advertise or accept respectively. See the documentation of these -configuration options for more information. +On the server side, the "promisor.advertise" and +"promisor.sendExtraFields" configuration options can be used to +control what it advertises. On the client side, the +"promisor.acceptFromServer" configuration option can be used to +control what it accepts. See the documentation of these configuration +options for more information. Note that in the future it would be nice if the "promisor-remote" protocol capability could be used by the server, when responding to diff --git a/promisor-remote.c b/promisor-remote.c index 0fb07f25af..424d88d4a1 100644 --- a/promisor-remote.c +++ b/promisor-remote.c @@ -314,6 +314,65 @@ static int allow_unsanitized(char ch) return ch > 32 && ch < 127; } +/* + * A valid extra field "foo" should correspond to a + * "remote..foo" config variable, so, like config variables + * keys, it should start with an alphabetic character and otherwise + * each character should satisfy is_config_key_char(). + */ +static int valid_extra_field(struct string_list_item *item, void *cb_data) +{ + const char *field = item->string; + const char *config_key = (const char *)cb_data; + + for (size_t i = 0; field[i]; i++) + if (i ? !is_config_key_char(field[i]) : !isalpha(field[i])) { + warning(_("invalid field '%s' in '%s' config"), field, config_key); + return 0; + } + return 1; +} + +static char *fields_from_config(struct string_list *fields_list, const char *config_key) +{ + char *extras = NULL; + + if (!git_config_get_string(config_key, &extras) && *extras) { + string_list_split_in_place(fields_list, extras, ", ", -1); + filter_string_list(fields_list, 0, valid_extra_field, (void *)config_key); + } + + return extras; +} + +static struct string_list *extra_fields_sent(void) +{ + static struct string_list fields_list = STRING_LIST_INIT_NODUP; + static int initialized = 0; + + if (!initialized) { + fields_from_config(&fields_list, "promisor.sendExtraFields"); + initialized = 1; + } + + return &fields_list; +} + +static void append_extra_fields(struct string_list *fields, + struct string_list *extra_fields, + const char *name) +{ + struct string_list_item *item; + + for_each_string_list_item(item, extra_fields) { + char *key = xstrfmt("remote.%s.%s", name, item->string); + const char *val; + if (!git_config_get_string_tmp(key, &val) && *val) + string_list_append(fields, item->string)->util = (char *)val; + free(key); + } +} + /* * Linked list for promisor remotes. * @@ -342,7 +401,8 @@ static void free_info_list(struct promisor_info *p) * remotes. For each promisor remote, some of its fields, starting * with "name" and "url", are put in the 'fields' string_list. */ -static struct promisor_info *promisor_info_list(struct repository *repo) +static struct promisor_info *promisor_info_list(struct repository *repo, + struct string_list *extra_fields) { struct promisor_info *infos = NULL; struct promisor_info **last_info = &infos; @@ -363,6 +423,9 @@ static struct promisor_info *promisor_info_list(struct repository *repo) string_list_append(&new_info->fields, "name")->util = (char *)r->name; string_list_append(&new_info->fields, "url")->util = (char *)url; + if (extra_fields) + append_extra_fields(&new_info->fields, extra_fields, r->name); + *last_info = new_info; last_info = &new_info->next; } @@ -385,7 +448,7 @@ char *promisor_remote_info(struct repository *repo) if (!advertise_promisors) return NULL; - info_list = promisor_info_list(repo); + info_list = promisor_info_list(repo, extra_fields_sent()); if (!info_list) return NULL; @@ -502,7 +565,7 @@ static void filter_promisor_remote(struct repository *repo, return; if (accept != ACCEPT_ALL) - info_list = promisor_info_list(repo); + info_list = promisor_info_list(repo, NULL); /* Parse remote info received */ @@ -519,13 +582,9 @@ static void filter_promisor_remote(struct repository *repo, elems = strbuf_split(remotes[i], ','); for (size_t j = 0; elems[j]; j++) { - int res; strbuf_strip_suffix(elems[j], ","); - res = skip_prefix(elems[j]->buf, "name=", &remote_name) || + if (!skip_prefix(elems[j]->buf, "name=", &remote_name)) skip_prefix(elems[j]->buf, "url=", &remote_url); - if (!res) - warning(_("unknown element '%s' from remote info"), - elems[j]->buf); } if (remote_name) diff --git a/t/t5710-promisor-remote-capability.sh b/t/t5710-promisor-remote-capability.sh index b35b774235..26f3c63112 100755 --- a/t/t5710-promisor-remote-capability.sh +++ b/t/t5710-promisor-remote-capability.sh @@ -289,6 +289,38 @@ test_expect_success "clone with 'KnownUrl' and empty url, so not advertised" ' check_missing_objects server 1 "$oid" ' +test_expect_success "clone with promisor.sendExtraFields" ' + git -C server config promisor.advertise true && + test_when_finished "rm -rf client" && + + git -C server remote add otherLop "https://invalid.invalid" && + git -C server config remote.otherLop.id "fooBar" && + git -C server config remote.otherLop.stuff "baz" && + git -C server config remote.otherLop.partialCloneFilter "blob:limit=10k" && + test_when_finished "git -C server remote remove otherLop" && + git -C server config promisor.sendExtraFields "id, partialCloneFilter" && + test_when_finished "git -C server config unset promisor.sendExtraFields" && + test_when_finished "rm trace" && + + # Clone from server to create a client + GIT_TRACE_PACKET="$(pwd)/trace" GIT_NO_LAZY_FETCH=0 git clone \ + -c remote.lop.promisor=true \ + -c remote.lop.fetch="+refs/heads/*:refs/remotes/lop/*" \ + -c remote.lop.url="file://$(pwd)/lop" \ + -c promisor.acceptfromserver=All \ + --no-local --filter="blob:limit=5k" server client && + + # Check that extra fields are properly transmitted + ENCODED_URL=$(echo "file://$(pwd)/lop" | sed -e "s/ /%20/g") && + PR1="name=lop,url=$ENCODED_URL,partialCloneFilter=blob:none" && + PR2="name=otherLop,url=https://invalid.invalid,id=fooBar,partialCloneFilter=blob:limit=10k" && + test_grep "clone< promisor-remote=$PR1;$PR2" trace && + test_grep "clone> promisor-remote=lop;otherLop" trace && + + # Check that the largest object is still missing on the server + check_missing_objects server 1 "$oid" +' + test_expect_success "clone with promisor.advertise set to 'true' but don't delete the client" ' git -C server config promisor.advertise true && From patchwork Mon Apr 14 16:03:43 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Couder X-Patchwork-Id: 14050669 Received: from mail-wr1-f51.google.com (mail-wr1-f51.google.com [209.85.221.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0BE7A274FDD for ; Mon, 14 Apr 2025 16:04:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744646662; cv=none; b=eTzCNA3hNKX6II+QuYA65xV8gEruG/jmOWyKlPmXuDA8SbcUY/BLd72cuJIViR03IlnE+fJyLezFAjVR6b/XL167kZXh61/cqz4Y06p5O48fKXaYf1VwYFCqW1C2uLx8xo5+B05ZbW0CzwDlvADgHrddoDuSC/lOpqwL+xHlZn0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744646662; c=relaxed/simple; bh=6OdCY7lJNau1sdct+Tne1pviPwRPCrStnBLBFQYYwZI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uLYR5deARhrqNHHTal5m/tYuTvA7Ze+T+udAGPk0xD968oLHpDO/ExFjs/aV0eK/c0jeBIzSmMic+5neHMYU4E0cqdO7djXKt9nOAppS6EvDIiX8/mY3kFVNrNdUWcr/IiTHhmoDsctjNcwVYGw++tsw5qWQ1Jlj7OoQcjAU7uI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=fO+3LPcC; arc=none smtp.client-ip=209.85.221.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="fO+3LPcC" Received: by mail-wr1-f51.google.com with SMTP id ffacd0b85a97d-39c1efbefc6so2685639f8f.1 for ; Mon, 14 Apr 2025 09:04:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1744646657; x=1745251457; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=jPOCgMRAMAj6oIp2oaeafLCaj6yIbtKAFYzkOPz+III=; b=fO+3LPcCtrX8n1A3jeq8u8rGLGcKAe1m+t5pPITdP6vuKG8zqbPChW2KyNjsmE7Efr IvWmmMFQQ97fBW6kbeWIopWOVjijoNfpycTSCl5iWc9cED1GeD8NxNUPXyApEL6eLzCC FxjIwtWdtf66YK7wzC8Oc1/Y2hamDPlxOt7V3HmYBQdF7MNGN1aiCR3EjNpr6qCWSnUz gMH4JEM/2+8KS3bgBIvGkEMU2pQ5uHTb1GlbcrWcr77GguqBif//Kq2pTzmb2rU1Ed0V e+G70BFKOohiPiwW8F0pPIir5WEIKoRbTwncpKUE5ebP1hwaRmJ0Fc6/kyDJ+y7TRvla rw0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744646657; x=1745251457; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=jPOCgMRAMAj6oIp2oaeafLCaj6yIbtKAFYzkOPz+III=; b=A3l+Z44TdHbNa0BzVEDNrfWpCZ5rNwr26w2CiLW/CLok/fXP+ny7LnVNfdvAOcLycy vSkJRU/dx5XGKKXdH7fuHJ9fkB3kxqTOuUip26yhc9Y8gbemRlSMcPtUGWxV9+oFjIal 7UQ+39nyTITAlHZTpqMhAILTDcfN03UFQ7o6VmkHh0DyEjwutdy+u9EK1pI9b6sWI4YJ KkIRef9kZpq5xDoRsKu2zjll57cPad477iazCCvqH9FaiS7KsMZt+zZ+RF07dpSTayfw M7K3CZMM0Jdpg0KoTyE9IZz224+5vPOteGQvxvMD8SR9NWVXW+RwgEZHPqCPa/vgxMzO gbhQ== X-Gm-Message-State: AOJu0YysUQl/XldmW5idobPMSnF1eabZadl4vnmUc2vqKdP84WQRmY0I VgT/PuNe+B+2PDhF0FdJ21ziTfDMmB6nzYmGpiUhfGfP8B+rBEv0vw7XYw== X-Gm-Gg: ASbGncuse51kgBuzcpHRsFfBPrTo6P5KZVdClSkGOn0bsi+7nMV9W4+tK/ziEclDjAk 8T3bwPulTsRzv3ORU6VJv5Y03SkTDSBY2Ogw6wlR5S+I8/d1TFs6jeJyoBbH4mXWyvWnh5OtpxT pq4Ldt7zieH7X4HaojfWGI2W0V+8ijR/eY/OqwjLlM2nu4Bv5NoqA6f7JxT5Pyv3veLrl0R/LKF EhXO+SQjikg/VnWx4gPbJe8IF02DnHgLP2qTuQKaP8r4oNkrGzO5MeMiUzir24mac55HBhZjbA+ CG33AYQiyiTsBJhemx+PjkUnCVSxSI9PdR7dqFT+cgG0bKiiij9MApymjWB54OoKq0tChPVWvHI = X-Google-Smtp-Source: AGHT+IGeV+2ChvVraiPadqt3IkuZnuf+uMusGVq/9tptAJvet7N/FVDl4CTYB4hGH7bz+zJAsXWwXA== X-Received: by 2002:a05:6000:2912:b0:38f:37f3:5ca9 with SMTP id ffacd0b85a97d-39eaaec991cmr8044605f8f.50.1744646656545; Mon, 14 Apr 2025 09:04:16 -0700 (PDT) Received: from christian-Precision-5550.lan ([2001:861:3f04:7ca0:a9d4:af7b:bb5c:77e4]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-39eae977513sm11258029f8f.42.2025.04.14.09.04.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Apr 2025 09:04:13 -0700 (PDT) From: Christian Couder To: git@vger.kernel.org Cc: Junio C Hamano , Patrick Steinhardt , Taylor Blau , Karthik Nayak , Christian Couder , Christian Couder Subject: [PATCH 4/4] promisor-remote: allow a client to check extra fields Date: Mon, 14 Apr 2025 18:03:43 +0200 Message-ID: <20250414160343.2216312-5-christian.couder@gmail.com> X-Mailer: git-send-email 2.49.0.158.gd3b09c1afe In-Reply-To: <20250414160343.2216312-1-christian.couder@gmail.com> References: <20250414160343.2216312-1-christian.couder@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 A previous commit allowed a server to pass extra fields through the "promisor-remote" protocol capability after the "name" and "url" fields. Let's make it possible for a client to check if these extra fields match what it expects before accepting a promisor remote. We allow this by introducing a new "promisor.checkExtraFields" configuration variable. It should contain a comma or space separated list of fields that will be checked. Signed-off-by: Christian Couder --- Documentation/config/promisor.adoc | 17 +++++ promisor-remote.c | 102 +++++++++++++++++++++++--- t/t5710-promisor-remote-capability.sh | 35 +++++++++ 3 files changed, 143 insertions(+), 11 deletions(-) diff --git a/Documentation/config/promisor.adoc b/Documentation/config/promisor.adoc index bc08999733..75207de2ac 100644 --- a/Documentation/config/promisor.adoc +++ b/Documentation/config/promisor.adoc @@ -43,3 +43,20 @@ promisor.acceptFromServer:: lazily fetchable from this promisor remote from its responses to "fetch" and "clone" requests from the client. Name and URL comparisons are case sensitive. See linkgit:gitprotocol-v2[5]. + +promisor.checkExtraFields:: + A comma or space separated list of additional remote related + fields that a client will check before accepting a promisor + remote. When a field named "bar" is part of this list and a + corresponding "remote.foo.bar" config variable is set for + locally for remote "foo", then the value of the + "remote.foo.bar" config variable will be checked against the + value of the "bar" field passed by the server through the + "promisor-remote" capability for the remote "foo". The remote + "foo" will be rejected if the values don't match. The fields + should be passed by the server through the "promisor-remote" + capability by using the `promisor.sendExtraFields` config + variable, see above. The extra fields will be checked only if + the `promisor.acceptFromServer` config variable, see above, is + not set to "None". If is set to "None", this config variable + will have no effect. See linkgit:gitprotocol-v2[5]. diff --git a/promisor-remote.c b/promisor-remote.c index 424d88d4a1..3645093f2f 100644 --- a/promisor-remote.c +++ b/promisor-remote.c @@ -358,6 +358,19 @@ static struct string_list *extra_fields_sent(void) return &fields_list; } +static struct string_list *extra_fields_checked(void) +{ + static struct string_list fields_list = STRING_LIST_INIT_NODUP; + static int initialized = 0; + + if (!initialized) { + fields_from_config(&fields_list, "promisor.checkExtraFields"); + initialized = 1; + } + + return &fields_list; +} + static void append_extra_fields(struct string_list *fields, struct string_list *extra_fields, const char *name) @@ -497,15 +510,65 @@ enum accept_promisor { ACCEPT_ALL }; +static int check_extra_field_one(struct string_list_item *item_value, + struct promisor_info *p) +{ + struct string_list_item *item; + + item = unsorted_string_list_lookup(&p->fields, item_value->string); + if (!item) + return 0; + + return !strcmp(item->util, item_value->util); +} + + +static int check_extra_field(struct string_list_item *item_value, + struct promisor_info *p, int in_list) +{ + if (!in_list) + return check_extra_field_one(item_value, p); + + for (; p; p = p->next) + if (check_extra_field_one(item_value, p)) + return 1; + + return 0; +} + +static int check_all_extra_fields(struct string_list* extra_values, + struct promisor_info *p, + int in_list) +{ + struct string_list* fields_checked = extra_fields_checked(); + struct string_list_item *item_checked; + + string_list_sort(extra_values); + + for_each_string_list_item(item_checked, fields_checked) { + struct string_list_item *item_value; + + item_value = string_list_lookup(extra_values, item_checked->string); + if (!item_value) + return 0; + if (!check_extra_field(item_value, p, in_list)) + return 0; + } + + return 1; +} + static int should_accept_remote(enum accept_promisor accept, - const char *remote_name, const char *remote_url, + const char *remote_name, + const char *remote_url, + struct string_list* extras, struct promisor_info *info_list) { struct promisor_info *p; const char *local_url; if (accept == ACCEPT_ALL) - return 1; + return check_all_extra_fields(extras, info_list, 1); p = remote_nick_find(info_list, remote_name); @@ -514,7 +577,7 @@ static int should_accept_remote(enum accept_promisor accept, return 0; if (accept == ACCEPT_KNOWN_NAME) - return 1; + return check_all_extra_fields(extras, p, 0); if (accept != ACCEPT_KNOWN_URL) BUG("Unhandled 'enum accept_promisor' value '%d'", accept); @@ -530,7 +593,7 @@ static int should_accept_remote(enum accept_promisor accept, local_url = p->fields.items[1].util; if (!strcmp(local_url, remote_url)) - return 1; + return check_all_extra_fields(extras, p, 0); warning(_("known remote named '%s' but with URL '%s' instead of '%s'"), remote_name, local_url, remote_url); @@ -564,9 +627,6 @@ static void filter_promisor_remote(struct repository *repo, if (accept == ACCEPT_NONE) return; - if (accept != ACCEPT_ALL) - info_list = promisor_info_list(repo, NULL); - /* Parse remote info received */ remotes = strbuf_split_str(info, ';', 0); @@ -577,14 +637,27 @@ static void filter_promisor_remote(struct repository *repo, const char *remote_url = NULL; char *decoded_name = NULL; char *decoded_url = NULL; + struct string_list extras = STRING_LIST_INIT_NODUP; strbuf_strip_suffix(remotes[i], ";"); elems = strbuf_split(remotes[i], ','); for (size_t j = 0; elems[j]; j++) { + char *p; + strbuf_strip_suffix(elems[j], ","); - if (!skip_prefix(elems[j]->buf, "name=", &remote_name)) - skip_prefix(elems[j]->buf, "url=", &remote_url); + if (skip_prefix(elems[j]->buf, "name=", &remote_name) || + skip_prefix(elems[j]->buf, "url=", &remote_url)) + continue; + + p = strchr(elems[j]->buf, '='); + if (p) { + *p = '\0'; + string_list_append(&extras, elems[j]->buf)->util = p + 1; + } else { + warning(_("invalid element '%s' from remote info"), + elems[j]->buf); + } } if (remote_name) @@ -592,9 +665,16 @@ static void filter_promisor_remote(struct repository *repo, if (remote_url) decoded_url = url_percent_decode(remote_url); - if (decoded_name && should_accept_remote(accept, decoded_name, decoded_url, info_list)) - strvec_push(accepted, decoded_name); + if (decoded_name) { + if (!info_list) + info_list = promisor_info_list(repo, extra_fields_checked()); + + if (should_accept_remote(accept, decoded_name, decoded_url, + &extras, info_list)) + strvec_push(accepted, decoded_name); + } + string_list_clear(&extras, 0); strbuf_list_free(elems); free(decoded_name); free(decoded_url); diff --git a/t/t5710-promisor-remote-capability.sh b/t/t5710-promisor-remote-capability.sh index 26f3c63112..858b34587d 100755 --- a/t/t5710-promisor-remote-capability.sh +++ b/t/t5710-promisor-remote-capability.sh @@ -321,6 +321,41 @@ test_expect_success "clone with promisor.sendExtraFields" ' check_missing_objects server 1 "$oid" ' +test_expect_success "clone with promisor.checkExtraFields" ' + git -C server config promisor.advertise true && + test_when_finished "rm -rf client" && + + git -C server remote add otherLop "https://invalid.invalid" && + git -C server config remote.otherLop.id "fooBar" && + git -C server config remote.otherLop.stuff "baz" && + git -C server config remote.otherLop.partialCloneFilter "blob:limit=10k" && + test_when_finished "git -C server remote remove otherLop" && + git -C server config promisor.sendExtraFields "id, partialCloneFilter" && + test_when_finished "git -C server config unset promisor.sendExtraFields" && + test_when_finished "rm trace" && + + # Clone from server to create a client + GIT_TRACE_PACKET="$(pwd)/trace" GIT_NO_LAZY_FETCH=0 git clone \ + -c remote.lop.promisor=true \ + -c remote.lop.fetch="+refs/heads/*:refs/remotes/lop/*" \ + -c remote.lop.url="file://$(pwd)/lop" \ + -c remote.lop.partialCloneFilter="blob:none" \ + -c promisor.acceptfromserver=All \ + -c promisor.checkExtraFields=partialCloneFilter \ + --no-local --filter="blob:limit=5k" server client && + + # Check that extra fields are properly transmitted + ENCODED_URL=$(echo "file://$(pwd)/lop" | sed -e "s/ /%20/g") && + PR1="name=lop,url=$ENCODED_URL,partialCloneFilter=blob:none" && + PR2="name=otherLop,url=https://invalid.invalid,id=fooBar,partialCloneFilter=blob:limit=10k" && + test_grep "clone< promisor-remote=$PR1;$PR2" trace && + test_grep "clone> promisor-remote=lop" trace && + test_grep ! "clone> promisor-remote=lop;otherLop" trace && + + # Check that the largest object is still missing on the server + check_missing_objects server 1 "$oid" +' + test_expect_success "clone with promisor.advertise set to 'true' but don't delete the client" ' git -C server config promisor.advertise true &&