From patchwork Sun Mar 17 03:48:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dragan Simic X-Patchwork-Id: 13594511 Received: from mail.manjaro.org (mail.manjaro.org [116.203.91.91]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D1AE65240 for ; Sun, 17 Mar 2024 03:48:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=116.203.91.91 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710647301; cv=none; b=J4xV+09wnys92vwWnJLXBGDmw1Wh8+c3XB4x8jHVXQCaBx6sVCxD8DpEG8gOVNlwPbMK6jkreFlGExG62Gau5CyFv17QVwgEQr7dUuCn6RY7aAZYOv9Gkwc+A9gMC+BGZ4il3CRUY4sgqS87Bu4cbEPtrxMQR/MEjPUSSHQMpgY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710647301; c=relaxed/simple; bh=hWIqF1G6J+zxqjxWEIcRXuT+KhKLX5Z670DrgWCGogI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=WQs/BF/VaQQ+bbjSoKb4eqGAM9ruoK2Gx5QnCMft+ip6q95fO7i84uDA5o1hULPZole6vXeYoXwbe6Hq/pRIoXkNgbP6yKvbDlxy+K9+Bd96yWJVAUYL5KdPnuFQjlDF0m3dEaWpWBM9pdTmjqSMwoDQdqtZN8fpKNpnAH1t0DY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=manjaro.org; spf=pass smtp.mailfrom=manjaro.org; dkim=pass (2048-bit key) header.d=manjaro.org header.i=@manjaro.org header.b=VfHXHjME; arc=none smtp.client-ip=116.203.91.91 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=manjaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=manjaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=manjaro.org header.i=@manjaro.org header.b="VfHXHjME" From: Dragan Simic DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=manjaro.org; s=2021; t=1710647291; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ZWCU9Z4P7lG568CX/f5aKgQOUMsOeocYsvo7VWTVXh8=; b=VfHXHjME6W8iZ4DKZJA5u22YB5tnoT69ciY8Zr4MUFZjcoeEO4YEu4GQiVwwqW5Xi/XmUm I0/QVm2J0NV+9u7KgfMumZTfUBoSNWuSuvvC1JsUr/iUbbK2na+Q2Bg0Dk4RAFt6HRbarY srpwCav+5ePaA4prRmb7WuM+4N5B4NQmOnSD6VkGeURLs0wFxqhNxSKmYMjUWgvX5+Bkz9 3biX4bGjpZILGiyw9KkVLoE80ElQwKlFlX3+PcKIJ1QlIaPWNoKelyEUe6LQkDct/KCrZC KrG9CaxofsZvTkIHs0mSD56vA+K+juaN3Q5/2f2sz7mYrTz63pTmhhTrIN8JGA== To: git@vger.kernel.org Cc: gitster@pobox.com, rsbecker@nexbridge.com, github@seichter.de, sunshine@sunshineco.com Subject: [PATCH v2 1/5] config: minor addition of whitespace Date: Sun, 17 Mar 2024 04:48:01 +0100 Message-Id: <8275861d8c59d7030669a488d0b4b0beac110af2.1710646998.git.dsimic@manjaro.org> In-Reply-To: References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Authentication-Results: ORIGINATING; auth=pass smtp.auth=dsimic@manjaro.org smtp.mailfrom=dsimic@manjaro.org In general, binary operators should be enclosed in a pair of leading and trailing space characters. Thus, clean up one spotted expression that for some reason had a "bunched up" operator. Signed-off-by: Dragan Simic --- Notes: Changes in v2: - No changes were introduced config.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config.c b/config.c index 3cfeb3d8bd99..a86a20cdf5cb 100644 --- a/config.c +++ b/config.c @@ -869,7 +869,7 @@ static char *parse_value(struct config_source *cs) continue; } if (c == '"') { - quote = 1-quote; + quote = 1 - quote; continue; } strbuf_addch(&cs->value, c); From patchwork Sun Mar 17 03:48:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dragan Simic X-Patchwork-Id: 13594512 Received: from mail.manjaro.org (mail.manjaro.org [116.203.91.91]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A964C5258 for ; Sun, 17 Mar 2024 03:48:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=116.203.91.91 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710647301; cv=none; b=S+pQs13OYSay7UWu/+9FBgyg/R3k+csjC0ncSa3rRDv9G7OM2/GHae89Fy/yakoUUw6ZJ7AeiDs5UcUybLxvh2rSenxXdHLjbxTv2q4QcRHXnzfdsNuAU/hvfocfnAvGQ4Ed2pCBHNv07KLUyrseyCoArF1JWNspk6I8qQDX8PM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710647301; c=relaxed/simple; bh=W7YS4SpRX9uumS3hTpVH83z6p6xZtQZaTvRjpxnegUg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=C3jvImvT74mzaLQ9cZY1vK6wLCJkU0urYgm0IPkd1fWJNlp1MlGnoDeyR15KqsMdcGJi3FwlEX4G3ciwNfsNy6t93cJY257uczeFrKnTFvdmp63TbnD19hPP2YOz/EPsRzkNIuwVhqNYLuCo2sJAe6dsUEK1Sc8qpUpIO3lYN/U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=manjaro.org; spf=pass smtp.mailfrom=manjaro.org; dkim=pass (2048-bit key) header.d=manjaro.org header.i=@manjaro.org header.b=h5bw9CIZ; arc=none smtp.client-ip=116.203.91.91 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=manjaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=manjaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=manjaro.org header.i=@manjaro.org header.b="h5bw9CIZ" From: Dragan Simic DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=manjaro.org; s=2021; t=1710647291; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=18Kx7ia0dA1ri52R0KNYdzNRxzen3KWEqy50aLs6CLc=; b=h5bw9CIZpeVKB57gYE4Za0+zrFe8eQCWuXDeyEz4rGX3NA37UiPCD/h9yZY5rvaPwrrx2u iZ9CnuI/E167yZpl7v310wLeJpNna1X0BzBDPiNBshrq9NnxtsfQYu3T87Hx86faph80zF dffEpGESgtG6XnxTGcZOv9qCFXAhgUqo3JW/vU/QBdwrsUqp8kSa5vFPa4QhnW85RiGmb+ D9IBh1TgdRfXVgdR4ylUDOCcnJyot+CPMt7SZ8LrQuJelADnPoS5wc28Yh26ytRehmjDj6 ZLbD01/bZVBBzRg8MimhyiFBKSo7YOgiK1+pFqFwgYGw4AcrAYX/tu7NM5znQw== To: git@vger.kernel.org Cc: gitster@pobox.com, rsbecker@nexbridge.com, github@seichter.de, sunshine@sunshineco.com Subject: [PATCH v2 2/5] config: really keep value-internal whitespace verbatim Date: Sun, 17 Mar 2024 04:48:02 +0100 Message-Id: In-Reply-To: References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Authentication-Results: ORIGINATING; auth=pass smtp.auth=dsimic@manjaro.org smtp.mailfrom=dsimic@manjaro.org Fix a bug in function parse_value() that prevented whitespace characters (i.e. spaces and horizontal tabs) found inside configuration option values from being parsed and returned in their original form. The bug caused any number of consecutive whitespace characters to be wrongly "squashed" into the same number of space characters. This bug was introduced back in July 2009, in commit ebdaae372b46 ("config: Keep inner whitespace verbatim"). Further investigation showed that setting a configuration value, by invoking git-config(1), converts value-internal horizontal tabs into "\t" escape sequences, which the buggy value-parsing logic in function parse_value() didn't "squash" into spaces. That's why the test included in the ebdaae37 commit passed, which presumably made the bug remain undetected for this long. On the other hand, value-internal literal horizontal tab characters, found in a configuration file edited by hand, do get "squashed" by the value-parsing logic, so the right choice was to fix this bug by making the value-internal whitespace characters preserved verbatim. Signed-off-by: Dragan Simic --- Notes: Changes in v2: - Dropped the "Fixes" tag, as explained and requested by Junio, [1] because having such tags actually doesn't help us in the long run - No changes to the source code were introduced [1] https://lore.kernel.org/git/xmqq4jd7qtg6.fsf@gitster.g/ config.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/config.c b/config.c index a86a20cdf5cb..5072f12e62e4 100644 --- a/config.c +++ b/config.c @@ -817,33 +817,38 @@ static int get_next_char(struct config_source *cs) static char *parse_value(struct config_source *cs) { - int quote = 0, comment = 0, space = 0; + int quote = 0, comment = 0; + size_t trim_len = 0; strbuf_reset(&cs->value); for (;;) { int c = get_next_char(cs); if (c == '\n') { if (quote) { cs->linenr--; return NULL; } + if (trim_len) + strbuf_setlen(&cs->value, trim_len); return cs->value.buf; } if (comment) continue; if (isspace(c) && !quote) { + if (!trim_len) + trim_len = cs->value.len; if (cs->value.len) - space++; + strbuf_addch(&cs->value, c); continue; } if (!quote) { if (c == ';' || c == '#') { comment = 1; continue; } } - for (; space; space--) - strbuf_addch(&cs->value, ' '); + if (trim_len) + trim_len = 0; if (c == '\\') { c = get_next_char(cs); switch (c) { From patchwork Sun Mar 17 03:48:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dragan Simic X-Patchwork-Id: 13594514 Received: from mail.manjaro.org (mail.manjaro.org [116.203.91.91]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A961A524A for ; Sun, 17 Mar 2024 03:48:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=116.203.91.91 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710647302; cv=none; b=jpubGagtJ5ZZvn5hsOPK2mFXa9wzKgg9wLKV4JFBQJhbWKy+GrekfsH959CLMv8Kph7iVptivGmKjR2I0K4fAR2p+q+vEj0HHxpUuJpfjyINm6TbTZc7tK7P8zaibhqqNHGjTNJPCcYpOb29VhF6NZvBgVZ6QfMTWWaey0Hx5OU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710647302; c=relaxed/simple; bh=akpAulV3PCDGqkBRqbxqCpnOrddwv0AxTcd97t4/tQI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=M20SHS0MPXrtCVWqag9+wa36mzX015PdCgA4PS4KwtmEhO0hzXgg8SOJBkCBrKS7FzqreixzgVek9mQMw00Fbi4YM87qi56PGVslQN3E/o5o7SSimygI8viFwB1wGqajjEMdcGrBjvNwSUXqyVjDMxoawC5K6AmLnI3SFa3lnpg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=manjaro.org; spf=pass smtp.mailfrom=manjaro.org; dkim=pass (2048-bit key) header.d=manjaro.org header.i=@manjaro.org header.b=haDdhHDS; arc=none smtp.client-ip=116.203.91.91 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=manjaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=manjaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=manjaro.org header.i=@manjaro.org header.b="haDdhHDS" From: Dragan Simic DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=manjaro.org; s=2021; t=1710647292; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=8RWjqsACRHdbiKwEMfRlL+XmBJOHm7l7pfVJruBv3Uk=; b=haDdhHDSSwBM7syQ7K+4n2fahM2Q2Pqz4vF3oaLCNwu5Ok19thWrOET9Ss7ou54+x3YRPR uSDI/izTq6N2ZuuKTxfiT/S95afbiwDuQWzE9HaKO96FXlWevZceo0tCdPfSPJZLjGpKSU VXgZRRtMqar/68/MggfyYlyaa4mSu6PF4TccewA7zB82aSi3WjnwZchlUxshDggvoTwTsO 7XVvJ8ep/77e5FvWkI6mwtZS9e+ZG4Jr8v1IkUS64W4LRV/B6fnyl08rJAU39pfWse7gz6 5jJlnhf1mfvE5DwY/+aqeLP8LXYG7tYaeXfEsXYBriN66fFdkidy6OCtIW6udw== To: git@vger.kernel.org Cc: gitster@pobox.com, rsbecker@nexbridge.com, github@seichter.de, sunshine@sunshineco.com Subject: [PATCH v2 3/5] test: introduce new x_to_tab() helper function Date: Sun, 17 Mar 2024 04:48:03 +0100 Message-Id: <480b46f2db82ea9c6cd9bbc2423923f81f2d36f5.1710646998.git.dsimic@manjaro.org> In-Reply-To: References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Authentication-Results: ORIGINATING; auth=pass smtp.auth=dsimic@manjaro.org smtp.mailfrom=dsimic@manjaro.org There's nothing wrong with the already existing q_to_tab() function, except when it's used on strings that contain uppercase letter "Q" in its literal meaning, which, for example, can happen with git configurations that contain "*.*Quoted" as the names of their configuration variables. Thus, let's introduce new x_to_tab() helper function that does pretty much the same job as the already existing q_to_tab() helper function, except for replacing "X" with a horizontal tab (HT), instead of replacing "Q". Signed-off-by: Dragan Simic --- Notes: This patch didn't exist in the v1 of this patch series. t/test-lib-functions.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh index 6eaf116346be..362d3205b7b0 100644 --- a/t/test-lib-functions.sh +++ b/t/test-lib-functions.sh @@ -107,6 +107,10 @@ q_to_tab () { tr Q '\011' } +x_to_tab () { + tr X '\011' +} + qz_to_tab_space () { tr QZ '\011\040' } From patchwork Sun Mar 17 03:48:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dragan Simic X-Patchwork-Id: 13594515 Received: from mail.manjaro.org (mail.manjaro.org [116.203.91.91]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 082D9538A for ; Sun, 17 Mar 2024 03:48:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=116.203.91.91 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710647303; cv=none; b=tq1+Dn7rCYhDVRd8bQLIwAH5DSvaXYKg5kZ4mrVKhzQOYENtTdqQYiGKLBSyPdhNL6aXg4zAy3s5Emzmi1XSxZFkevazZ5SDWgip/SOCF2/RLHqTsGK0VWAfDJunVtXdgcmXOpqRMvB85J49btsLd6Biz4WoFOYsVIj3i/AXYOs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710647303; c=relaxed/simple; bh=x6e1n2AS2tXaPwLEaLUlLHRPslIke97AkD2+3cGQmoo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=GyYSMMhcm7fl0HMY/5/j7+bKSjWEoh/Gb7XVEaYq+RtoRCGufNnqxoqDQziX74PbeeK/KJskeKqCgq9An9OO/Zx7UqYXnkezpl85hWSMMYJ6D1jewkvNSE7TBXjLgTFVlmf7BKxL8JAmxhRYcW1QHyCaQDdq78YgmfSwDmlb3Ek= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=manjaro.org; spf=pass smtp.mailfrom=manjaro.org; dkim=pass (2048-bit key) header.d=manjaro.org header.i=@manjaro.org header.b=rEeVMGI8; arc=none smtp.client-ip=116.203.91.91 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=manjaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=manjaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=manjaro.org header.i=@manjaro.org header.b="rEeVMGI8" From: Dragan Simic DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=manjaro.org; s=2021; t=1710647292; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=bDQWs/4OAzKGh/iQ2dU/79kMHYpVuMJ+HGzZQhWpCKs=; b=rEeVMGI8dpQOnrWTOLX84DzeI6poMA6Kr4PpDTPfOT+yVXuDsqI3Ccpu+bB0uPNs6A5pSC KlcQLyRjUiUoLW0T8ZBhXEno2j9SoUeKtPQWUnUHiBKbhTCxnx2JBEZhL8TubPpF678LOh 2JQYC3g+nk4GgdxA8yVkEXxaT803PXQxpL4JLmajT6hg8Hhs/nORpd9Ssy1FUhJ8mLABoR rr04aauPl3dikOhaVAMY/BsailiF624eKa5dUf29zwBETgb5XkMGW4u951zQn7T8GlxPBc dZD4WzaLrDKH9oAYi5HSG6TkZ+2g+ZMsFo8jgTVqdEK82JcwoAqPspGk2YRi7Q== To: git@vger.kernel.org Cc: gitster@pobox.com, rsbecker@nexbridge.com, github@seichter.de, sunshine@sunshineco.com Subject: [PATCH v2 4/5] t1300: add more tests for whitespace and inline comments Date: Sun, 17 Mar 2024 04:48:04 +0100 Message-Id: <9a73e7d3cbb9ea210ed1098c5a304b0f5d5e1a2e.1710646998.git.dsimic@manjaro.org> In-Reply-To: References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Authentication-Results: ORIGINATING; auth=pass smtp.auth=dsimic@manjaro.org smtp.mailfrom=dsimic@manjaro.org Add a handful of additional automated tests, to improve the coverage of configuration file entries whose values contain internal whitespace, leading and/or trailing whitespace, which may or may not be enclosed within quotation marks, or which contain an additional inline comment. At the same time, rework one already existing automated test a bit, to ensure consistency with the newly added tests. This change introduced no functional changes to the already existing test. Helped-by: Eric Sunshine Signed-off-by: Dragan Simic --- Notes: Changes in v2: - All new tests and one already existing test reworked according to Eric Sunshine's review suggestions; [1][2] the already existing test was reworked a bit to ensure consistency - Added a Helped-by tag [1] https://lore.kernel.org/git/CAPig+cRMPNExbG34xJ0w5npUc3DDwxQUGS_AQfam_mi4s53=sA@mail.gmail.com/ [2] https://lore.kernel.org/git/CAPig+cRG8eFxepkaiN54H+fa7D=rFGsmEHdvTP+HSSaLO_6T_A@mail.gmail.com/ t/t1300-config.sh | 114 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 110 insertions(+), 4 deletions(-) diff --git a/t/t1300-config.sh b/t/t1300-config.sh index 31c387868708..37ed078721ea 100755 --- a/t/t1300-config.sh +++ b/t/t1300-config.sh @@ -11,7 +11,97 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh -test_expect_success 'clear default config' ' +test_expect_success 'create test configuration' ' + x_to_tab >.git/config <<-\EOF + [section] + Xsolid = rock + Xsparse = big XX blue + XsparseAndTail = big XX blue + XsparseAndTailQuoted = "big XX blue " + XsparseAndBiggerTail = big XX blue X X + XsparseAndBiggerTailQuoted = "big XX blue X X" + XsparseAndBiggerTailQuotedPlus = "big XX blue X X"X + XheadAndTail = Xbig blue + XheadAndTailQuoted = "Xbig blue " + XheadAndTailQuotedPlus = "Xbig blue " + Xannotated = big blueX# to be discarded + XannotatedQuoted = "big blue"X# to be discarded + EOF +' + +test_expect_success 'no internal whitespace' ' + echo "rock" >expect && + git config --get section.solid >actual && + test_cmp expect actual +' + +test_expect_success 'internal whitespace' ' + echo "big XX blue" | x_to_tab >expect && + git config --get section.sparse >actual && + test_cmp expect actual +' + +test_expect_success 'internal and trailing whitespace' ' + echo "big XX blue" | x_to_tab >expect && + git config --get section.sparseAndTail >actual && + test_cmp expect actual +' + +test_expect_success 'internal and trailing whitespace, all quoted' ' + echo "big XX blue " | x_to_tab >expect && + git config --get section.sparseAndTailQuoted >actual && + test_cmp expect actual +' + +test_expect_success 'internal and more trailing whitespace' ' + echo "big XX blue" | x_to_tab >expect && + git config --get section.sparseAndBiggerTail >actual && + test_cmp expect actual +' + +test_expect_success 'internal and more trailing whitespace, all quoted' ' + echo "big XX blue X X" | x_to_tab >expect && + git config --get section.sparseAndBiggerTailQuoted >actual && + test_cmp expect actual +' + +test_expect_success 'internal and more trailing whitespace, not all quoted' ' + echo "big XX blue X X" | x_to_tab >expect && + git config --get section.sparseAndBiggerTailQuotedPlus >actual && + test_cmp expect actual +' + +test_expect_success 'leading and trailing whitespace' ' + echo "big blue" | x_to_tab >expect && + git config --get section.headAndTail >actual && + test_cmp expect actual +' + +test_expect_success 'leading and trailing whitespace, all quoted' ' + echo "Xbig blue " | x_to_tab >expect && + git config --get section.headAndTailQuoted >actual && + test_cmp expect actual +' + +test_expect_success 'leading and trailing whitespace, not all quoted' ' + echo "Xbig blue " | x_to_tab >expect && + git config --get section.headAndTailQuotedPlus >actual && + test_cmp expect actual +' + +test_expect_success 'inline comment' ' + echo "big blue" | x_to_tab >expect && + git config --get section.annotated >actual && + test_cmp expect actual +' + +test_expect_success 'inline comment, quoted' ' + echo "big blue" | x_to_tab >expect && + git config --get section.annotatedQuoted >actual && + test_cmp expect actual +' + +test_expect_success 'clear default configuration' ' rm -f .git/config ' @@ -1066,9 +1156,25 @@ test_expect_success '--null --get-regexp' ' test_cmp expect result ' -test_expect_success 'inner whitespace kept verbatim' ' - git config section.val "foo bar" && - test_cmp_config "foo bar" section.val +test_expect_success 'inner whitespace kept verbatim, spaces only' ' + echo "foo bar" >expect && + git config section.val "foo bar" && + git config --get section.val >actual && + test_cmp expect actual +' + +test_expect_success 'inner whitespace kept verbatim, horizontal tabs only' ' + echo "fooQQbar" | q_to_tab >expect && + git config section.val "$(cat expect)" && + git config --get section.val >actual && + test_cmp expect actual +' + +test_expect_success 'inner whitespace kept verbatim, horizontal tabs and spaces' ' + echo "foo Q bar" | q_to_tab >expect && + git config section.val "$(cat expect)" && + git config --get section.val >actual && + test_cmp expect actual ' test_expect_success SYMLINKS 'symlinked configuration' ' From patchwork Sun Mar 17 03:48:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dragan Simic X-Patchwork-Id: 13594516 Received: from mail.manjaro.org (mail.manjaro.org [116.203.91.91]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 56EFCF510 for ; Sun, 17 Mar 2024 03:48:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=116.203.91.91 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710647305; cv=none; b=LHU8aFAJVJ5SFqyu9azpzjph1sfs6a8AuZD98KBEwoV4r6zr8TmH9XWn3rgDAa9lYbuRPUBZROOV/DAGCu6KHxGU0DYSD6nk4J0y9XHN+T8MoPwOHq3EaQGk2aGHJIx8BvkXeGsMf0fLmQZgUXFNsBFTMUL3HoZeT9ndKKaJKGA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710647305; c=relaxed/simple; bh=bfMqUooiRw/RNsr33+IRAqg00ygPGTU6NapqHVRDudc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=e1PWB1DGbFp5Ff4k7tkaSkFnS/YG86ydR+/RxrzJb+EoV0QxXWjlmLewscbgwFQV6iR2zDLGUK/+YRKFD/lRai6jiC/FQ/BMDCfVqOoDfMVYF64F8fTfvWuO1T2S1A3bIrSQHFm3dZyS8O9K5GNqzpQ9+VximBIXWd5Nd+bG9dk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=manjaro.org; spf=pass smtp.mailfrom=manjaro.org; dkim=pass (2048-bit key) header.d=manjaro.org header.i=@manjaro.org header.b=SfBsc4g9; arc=none smtp.client-ip=116.203.91.91 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=manjaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=manjaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=manjaro.org header.i=@manjaro.org header.b="SfBsc4g9" From: Dragan Simic DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=manjaro.org; s=2021; t=1710647293; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4Jv4wuO2E/x/EtdlWKN3ptgzVZrIQ+2mVNL2cFUHWO4=; b=SfBsc4g9K0Ppb6/fA36cybxZDyQmq83/nOH6d/Cdaw0Zfry7I2oecUR7ecyDwpJtkYXgBc ihpEurAOu9DQ0QFM1G7O6h3d0MGCQjsOOrelK2aCR5kve14Dmym8vNNqIxJUUudarMaCW2 W0npLAHXAQw2u0LAHEqj8DnpflPO8zwkcl7wRhp4JiCEqW8Ewk2PlzD8/542eBYs/sPAEs 0ayM8qlL2LZZN23Cep55dTyt1kJX5jK6t74farNGAJqgvAy4tsMyzbYP8mhUlAuDGdd+GV Eyf2nst7mhkddou80aEi1hdwyoUNdxcVx4gNC5QLMYljUd4b9pNbXGmlrMLKOg== To: git@vger.kernel.org Cc: gitster@pobox.com, rsbecker@nexbridge.com, github@seichter.de, sunshine@sunshineco.com Subject: [PATCH v2 5/5] config.txt: describe handling of whitespace further Date: Sun, 17 Mar 2024 04:48:05 +0100 Message-Id: <041e0bb6fd72d12318130e7010a75dc8321e2d34.1710646998.git.dsimic@manjaro.org> In-Reply-To: References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Authentication-Results: ORIGINATING; auth=pass smtp.auth=dsimic@manjaro.org smtp.mailfrom=dsimic@manjaro.org Make it more clear what the whitespace characters are in the context of git configuration files, and improve the description of the trailing whitespace handling a bit. Signed-off-by: Dragan Simic --- Notes: Changes in v2: - No changes were introduced Documentation/config.txt | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/Documentation/config.txt b/Documentation/config.txt index 782c2bab906c..20f3300dc706 100644 --- a/Documentation/config.txt +++ b/Documentation/config.txt @@ -22,9 +22,10 @@ multivalued. Syntax ~~~~~~ -The syntax is fairly flexible and permissive; whitespaces are mostly -ignored. The '#' and ';' characters begin comments to the end of line, -blank lines are ignored. +The syntax is fairly flexible and permissive. Whitespace characters, +which in this context are the space character (SP) and the horizontal +tabulation (HT), are mostly ignored. The '#' and ';' characters begin +comments to the end of line. Blank lines are ignored. The file consists of sections and variables. A section begins with the name of the section in square brackets and continues until the next @@ -64,12 +65,14 @@ The variable names are case-insensitive, allow only alphanumeric characters and `-`, and must start with an alphabetic character. A line that defines a value can be continued to the next line by -ending it with a `\`; the backslash and the end-of-line are -stripped. Leading whitespaces after 'name =', the remainder of the +ending it with a `\`; the backslash and the end-of-line are stripped. +Leading whitespace characters after 'name =', the remainder of the line after the first comment character '#' or ';', and trailing -whitespaces of the line are discarded unless they are enclosed in -double quotes. Internal whitespaces within the value are retained -verbatim. +whitespace characters of the line are discarded unless they are enclosed +in double quotes. The discarding of the trailing whitespace characters +applies regardless of the discarding of the portion of the line after +the first comment character. Internal whitespace characters within the +value are retained verbatim. Inside double quotes, double quote `"` and backslash `\` characters must be escaped: use `\"` for `"` and `\\` for `\`.