All of lore.kernel.org
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Ignacio Encinas <ignacio@iencinas.com>
Cc: git@vger.kernel.org
Subject: Re: [RFC PATCH 1/1] config: learn the "hostname:" includeIf condition
Date: Thu, 07 Mar 2024 13:40:04 -0800	[thread overview]
Message-ID: <xmqqil1xk9fv.fsf@gitster.g> (raw)
In-Reply-To: <20240307205006.467443-2-ignacio@iencinas.com> (Ignacio Encinas's message of "Thu, 7 Mar 2024 21:50:06 +0100")

Ignacio Encinas <ignacio@iencinas.com> writes:

> Currently, customizing the configuration depending on the machine running
> git has to be done manually.
>
> Add support for a new includeIf keyword "hostname:" to conditionally
> include configuration files depending on the hostname.
>
> Signed-off-by: Ignacio Encinas <ignacio@iencinas.com>
> ---
>  Documentation/config.txt  |  9 +++++++++
>  config.c                  | 16 ++++++++++++++++
>  t/t1305-config-include.sh | 22 ++++++++++++++++++++++
>  3 files changed, 47 insertions(+)
>
> diff --git a/Documentation/config.txt b/Documentation/config.txt
> index e3a74dd1c1..9a22fd2609 100644
> --- a/Documentation/config.txt
> +++ b/Documentation/config.txt
> @@ -186,6 +186,11 @@ As for the naming of this keyword, it is for forwards compatibility with
>  a naming scheme that supports more variable-based include conditions,
>  but currently Git only supports the exact keyword described above.

> +`hostname`::
> +	The data that follows the keyword `hostname:` is taken to be a
> +	pattern with standard globbing wildcards. If the current
> +	hostname matches the pattern, the include condition is met.
> +

OK.  This seems to copy its phrasing from the existing text for
"gitdir" and "onbranch", which greatly helps the description for
these features consistent.

> diff --git a/config.c b/config.c
> index 3cfeb3d8bd..e0611fc342 100644
> --- a/config.c
> +++ b/config.c
> @@ -317,6 +317,20 @@ static int include_by_branch(const char *cond, size_t cond_len)
>  	return ret;
>  }
>  
> +static int include_by_hostname(const char *cond, size_t cond_len)
> +{
> +	int ret;
> +	char my_host[HOST_NAME_MAX + 1];
> +	struct strbuf pattern = STRBUF_INIT;
> +	if (xgethostname(my_host, sizeof(my_host)))
> +		return 0;
> +
> +	strbuf_add(&pattern, cond, cond_len);
> +	ret = !wildmatch(pattern.buf, my_host, 0);
> +	strbuf_release(&pattern);
> +	return ret;
> +}

Have a blank line between the end of the decl block (our codebase
frowns upon decl-after-statement) and the first statement,
i.e. before "if (xgethostname...".

Otherwise this looks reasonable to me.

> diff --git a/t/t1305-config-include.sh b/t/t1305-config-include.sh
> index 5cde79ef8c..ee78d9cade 100755
> --- a/t/t1305-config-include.sh
> +++ b/t/t1305-config-include.sh
> @@ -357,4 +357,26 @@ test_expect_success 'include cycles are detected' '
>  	grep "exceeded maximum include depth" stderr
>  '
>  
> +test_expect_success 'conditional include, hostname' '
> +	echo "[includeIf \"hostname:$(hostname)a\"]path=bar12" >>.git/config &&
> +	echo "[test]twelve=12" >.git/bar12 &&
> +	test_must_fail git config test.twelve &&

Emulating other tests in this file that uses here document may make
it a bit easier to read?  E.g.,

	cat >>.gitconfig <<-EOF &&
	[includeIf "hostname:$(hostname)a"]
		path = bar12
	EOF

> +	echo "[includeIf \"hostname:$(hostname)\"]path=bar12" >>.git/config &&

Ditto for the remainder of the patch.

Thanks.


  reply	other threads:[~2024-03-07 21:40 UTC|newest]

Thread overview: 51+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-07 20:50 [RFC PATCH 0/1] Add hostname condition to includeIf Ignacio Encinas
2024-03-07 20:50 ` [RFC PATCH 1/1] config: learn the "hostname:" includeIf condition Ignacio Encinas
2024-03-07 21:40   ` Junio C Hamano [this message]
2024-03-09 10:47     ` Ignacio Encinas Rubio
2024-03-09 17:38       ` Junio C Hamano
2024-03-09 18:18 ` [PATCH v2 0/1] Add hostname condition to includeIf Ignacio Encinas
2024-03-09 18:18   ` [PATCH v2 1/1] config: learn the "hostname:" includeIf condition Ignacio Encinas
2024-03-10 16:59     ` Junio C Hamano
2024-03-10 18:46       ` Ignacio Encinas Rubio
2024-03-11 17:39         ` Junio C Hamano
2024-03-13 21:53           ` Ignacio Encinas Rubio
2024-03-16  6:57     ` Jeff King
2024-03-16 11:19       ` Ignacio Encinas Rubio
2024-03-16 16:00         ` Taylor Blau
2024-03-16 16:46           ` Ignacio Encinas Rubio
2024-03-16 17:02       ` Junio C Hamano
2024-03-16 17:41         ` rsbecker
2024-03-16 18:05           ` Ignacio Encinas Rubio
2024-03-16 18:49             ` rsbecker
2024-03-18  8:17         ` Jeff King
2024-03-16 16:01     ` Taylor Blau
2024-03-16 16:50       ` Ignacio Encinas Rubio
2024-03-19 18:37   ` [PATCH v3 0/2] Add hostname condition to includeIf Ignacio Encinas
2024-03-19 18:37     ` [PATCH v3 1/2] t: add a test helper for getting hostname Ignacio Encinas
2024-03-19 20:31       ` Junio C Hamano
2024-03-19 20:57         ` Jeff King
2024-03-19 21:00           ` Junio C Hamano
2024-03-19 21:11             ` Jeff King
2024-03-19 21:44               ` Junio C Hamano
2024-03-21  0:11                 ` Chris Torek
2024-03-19 20:56       ` Jeff King
2024-03-19 18:37     ` [PATCH v3 2/2] config: learn the "hostname:" includeIf condition Ignacio Encinas
2024-03-19 20:53       ` Junio C Hamano
2024-03-19 21:04       ` Jeff King
2024-03-19 21:32         ` Ignacio Encinas Rubio
2024-03-19 20:55     ` [PATCH v3 0/2] Add hostname condition to includeIf Eric Sunshine
2024-03-19 21:12       ` Junio C Hamano
2024-03-19 21:13         ` Eric Sunshine
2024-03-20  0:19           ` Jeff King
2024-03-20  2:49             ` Eric Sunshine
2024-03-20  3:07               ` Eric Sunshine
2024-03-20 14:34                 ` Chris Torek
2024-03-20 16:37                   ` Eric Sunshine
2024-03-20 20:51                     ` Jeff King
2024-03-20 16:49                   ` Junio C Hamano
2024-03-19 21:36         ` Dirk Gouders
2024-03-19 22:03           ` rsbecker
2024-03-19 22:26             ` Dirk Gouders
2024-03-19 22:31               ` rsbecker
2024-03-19 22:59                 ` Junio C Hamano
2024-03-19 21:22       ` Ignacio Encinas Rubio

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqqil1xk9fv.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=ignacio@iencinas.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.