* [PATCH] config: add "hostname" condition to includeIf
@ 2025-08-22 8:22 monarch
2025-08-22 8:22 ` [PATCH] Start 2.52 cycle, the first batch monarch
0 siblings, 1 reply; 6+ messages in thread
From: monarch @ 2025-08-22 8:22 UTC (permalink / raw)
To: git; +Cc: monarch
Teach "includeIf" to include configuration based on the machine's hostname,
as returned by gethostname(2).
Example:
[includeIf "hostname:work-laptop"]
path = ~/.gitconfig.work
[includeIf "hostname:home-pc"]
path = ~/.gitconfig.home
This allows users to write host-specific configuration without separate branches.
Signed-off-by: monarch <ayushoffinfo17@gmail•com>
---
config.c | 37 +++++++++++++++++++++++++++++++------
1 file changed, 31 insertions(+), 6 deletions(-)
diff --git a/config.c b/config.c
index e0ff35d426..dbc1a2bc75 100644
--- a/config.c
+++ b/config.c
@@ -7,6 +7,7 @@
*/
#include "git-compat-util.h"
+#include <unistd.h>
#include "abspath.h"
#include "date.h"
#include "branch.h"
@@ -391,23 +392,47 @@ static int include_by_remote_url(struct config_include_data *inc,
inc->remote_urls);
}
+static int include_by_hostname(const char *cond, size_t cond_len)
+{
+ char actual_hostname[1024];
+ struct strbuf target_hostname = STRBUF_INIT;
+ int ret = 0;
+
+ // Make sure the call to gethostname is correct and its return value is checked.
+ if (gethostname(actual_hostname, sizeof(actual_hostname)) != 0)
+ return 0; // If it fails, the condition is false.
+
+ strbuf_add(&target_hostname, cond, cond_len);
+
+ // The core of the logic: strcmp returns 0 when strings are equal.
+ if (strcmp(actual_hostname, target_hostname.buf) == 0)
+ ret = 1; // Success, the hostnames match!
+
+ strbuf_release(&target_hostname);
+ return ret;
+}
+
static int include_condition_is_true(const struct key_value_info *kvi,
- struct config_include_data *inc,
- const char *cond, size_t cond_len)
+ struct config_include_data *inc,
+ const char *cond, size_t cond_len)
{
- const struct config_options *opts = inc->opts;
+const struct config_options *opts = inc->opts;
+
+
if (skip_prefix_mem(cond, cond_len, "gitdir:", &cond, &cond_len))
return include_by_gitdir(kvi, opts, cond, cond_len, 0);
else if (skip_prefix_mem(cond, cond_len, "gitdir/i:", &cond, &cond_len))
return include_by_gitdir(kvi, opts, cond, cond_len, 1);
- else if (skip_prefix_mem(cond, cond_len, "onbranch:", &cond, &cond_len))
+ else if (skip_prefix_mem(cond, cond_len, "onbranch:", &cond, cond_len))
return include_by_branch(inc, cond, cond_len);
else if (skip_prefix_mem(cond, cond_len, "hasconfig:remote.*.url:", &cond,
- &cond_len))
+ &cond_len))
return include_by_remote_url(inc, cond, cond_len);
+ else if (skip_prefix_mem(cond, cond_len, "hostname:", &cond, &cond_len))
+ return include_by_hostname(cond, cond_len);
- /* unknown conditionals are always false */
+/* unknown conditionals are always false */
return 0;
}
--
2.43.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH] Start 2.52 cycle, the first batch
2025-08-22 8:22 [PATCH] config: add "hostname" condition to includeIf monarch
@ 2025-08-22 8:22 ` monarch
0 siblings, 0 replies; 6+ messages in thread
From: monarch @ 2025-08-22 8:22 UTC (permalink / raw)
To: git; +Cc: Junio C Hamano
From: Junio C Hamano <gitster@pobox•com>
Signed-off-by: Junio C Hamano <gitster@pobox•com>
---
Documentation/RelNotes/2.52.0.adoc | 58 ++++++++++++++++++++++++++++++
GIT-VERSION-GEN | 2 +-
RelNotes | 2 +-
3 files changed, 60 insertions(+), 2 deletions(-)
create mode 100644 Documentation/RelNotes/2.52.0.adoc
diff --git a/Documentation/RelNotes/2.52.0.adoc b/Documentation/RelNotes/2.52.0.adoc
new file mode 100644
index 0000000000..1919e039bd
--- /dev/null
+++ b/Documentation/RelNotes/2.52.0.adoc
@@ -0,0 +1,58 @@
+Git v2.52 Release Notes
+=======================
+
+UI, Workflows & Features
+------------------------
+
+
+Performance, Internal Implementation, Development Support etc.
+--------------------------------------------------------------
+
+ * string_list_split*() family of functions have been extended to
+ simplify common use cases.
+
+ * Arrays of strbuf is often a wrong data structure to use, and
+ strbuf_split*() family of functions that create them often have
+ better alternatives. Update several code paths and replace
+ strbuf_split*().
+
+ * Revision traversal limited with pathspec, like "git log dir/*",
+ used to ignore changed-paths Bloom filter when the pathspec
+ contained wildcards; now they take advantage of the filter when
+ they can.
+
+Fixes since v2.51
+-----------------
+
+Unless otherwise noted, all the changes in 2.51.X maintenance track,
+including security updates, are included in this release.
+
+ * During interactive rebase, using 'drop' on a merge commit lead to
+ an error, which was incorrect.
+ (merge 4d491ade8f js/rebase-i-allow-drop-on-a-merge later to maint).
+
+ * "git refs migrate" to migrate the reflog entries from a refs
+ backend to another had a handful of bugs squashed.
+ (merge 465eff81de ps/reflog-migrate-fixes later to maint).
+
+ * "git remote rename origin upstream" failed to move origin/HEAD to
+ upstream/HEAD when origin/HEAD is unborn and performed other
+ renames extremely inefficiently, which has been corrected.
+ (merge 16c4fa26b9 ps/remote-rename-fix later to maint).
+
+ * "git describe" has been optimized by using better data structure.
+ (merge 08bb69d70f rs/describe-with-prio-queue later to maint).
+
+ * "git push" had a code path that led to BUG() but it should have
+ been a die(), as it is a response to a usual but invalid end-user
+ action to attempt pushing an object that does not exist.
+ (merge dfbfc2221b dl/push-missing-object-error later to maint).
+
+ * Various bugs about rename handling in "ort" merge strategy have
+ been fixed.
+ (merge f6ecb603ff en/ort-rename-fixes later to maint).
+
+ * Other code cleanup, docfix, build fix, etc.
+ (merge 823d537fa7 kh/doc-git-log-markup-fix later to maint).
+ (merge cf7efa4f33 rj/t6137-cygwin-fix later to maint).
+ (merge 529a60a885 ua/t1517-short-help-tests later to maint).
diff --git a/GIT-VERSION-GEN b/GIT-VERSION-GEN
index 64cbc58335..b16db85e77 100755
--- a/GIT-VERSION-GEN
+++ b/GIT-VERSION-GEN
@@ -1,6 +1,6 @@
#!/bin/sh
-DEF_VER=v2.51.0
+DEF_VER=v2.51.GIT
LF='
'
diff --git a/RelNotes b/RelNotes
index 48f15770a4..6d16c0077a 120000
--- a/RelNotes
+++ b/RelNotes
@@ -1 +1 @@
-Documentation/RelNotes/2.51.0.adoc
\ No newline at end of file
+Documentation/RelNotes/2.52.0.adoc
\ No newline at end of file
--
2.43.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH] config: add "hostname" condition to includeIf
@ 2025-08-22 8:35 monarch
0 siblings, 0 replies; 6+ messages in thread
From: monarch @ 2025-08-22 8:35 UTC (permalink / raw)
To: git; +Cc: monarch
Teach "includeIf" to include configuration based on the machine's hostname,
as returned by gethostname(2).
Example:
[includeIf "hostname:work-laptop"]
path = ~/.gitconfig.work
[includeIf "hostname:home-pc"]
path = ~/.gitconfig.home
This allows users to write host-specific configuration without separate branches.
Signed-off-by: monarch <ayushoffinfo17@gmail•com>
---
config.c | 37 +++++++++++++++++++++++++++++++------
1 file changed, 31 insertions(+), 6 deletions(-)
diff --git a/config.c b/config.c
index e0ff35d426..dbc1a2bc75 100644
--- a/config.c
+++ b/config.c
@@ -7,6 +7,7 @@
*/
#include "git-compat-util.h"
+#include <unistd.h>
#include "abspath.h"
#include "date.h"
#include "branch.h"
@@ -391,23 +392,47 @@ static int include_by_remote_url(struct config_include_data *inc,
inc->remote_urls);
}
+static int include_by_hostname(const char *cond, size_t cond_len)
+{
+ char actual_hostname[1024];
+ struct strbuf target_hostname = STRBUF_INIT;
+ int ret = 0;
+
+ // Make sure the call to gethostname is correct and its return value is checked.
+ if (gethostname(actual_hostname, sizeof(actual_hostname)) != 0)
+ return 0; // If it fails, the condition is false.
+
+ strbuf_add(&target_hostname, cond, cond_len);
+
+ // The core of the logic: strcmp returns 0 when strings are equal.
+ if (strcmp(actual_hostname, target_hostname.buf) == 0)
+ ret = 1; // Success, the hostnames match!
+
+ strbuf_release(&target_hostname);
+ return ret;
+}
+
static int include_condition_is_true(const struct key_value_info *kvi,
- struct config_include_data *inc,
- const char *cond, size_t cond_len)
+ struct config_include_data *inc,
+ const char *cond, size_t cond_len)
{
- const struct config_options *opts = inc->opts;
+const struct config_options *opts = inc->opts;
+
+
if (skip_prefix_mem(cond, cond_len, "gitdir:", &cond, &cond_len))
return include_by_gitdir(kvi, opts, cond, cond_len, 0);
else if (skip_prefix_mem(cond, cond_len, "gitdir/i:", &cond, &cond_len))
return include_by_gitdir(kvi, opts, cond, cond_len, 1);
- else if (skip_prefix_mem(cond, cond_len, "onbranch:", &cond, &cond_len))
+ else if (skip_prefix_mem(cond, cond_len, "onbranch:", &cond, cond_len))
return include_by_branch(inc, cond, cond_len);
else if (skip_prefix_mem(cond, cond_len, "hasconfig:remote.*.url:", &cond,
- &cond_len))
+ &cond_len))
return include_by_remote_url(inc, cond, cond_len);
+ else if (skip_prefix_mem(cond, cond_len, "hostname:", &cond, &cond_len))
+ return include_by_hostname(cond, cond_len);
- /* unknown conditionals are always false */
+/* unknown conditionals are always false */
return 0;
}
--
2.43.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH] config: add "hostname" condition to includeIf
@ 2025-08-22 8:49 monarch
2025-08-27 19:23 ` Ayush Sharma
0 siblings, 1 reply; 6+ messages in thread
From: monarch @ 2025-08-22 8:49 UTC (permalink / raw)
To: git; +Cc: monarch
Teach "includeIf" to include configuration based on the machine's hostname,
as returned by gethostname(2).
Example:
[includeIf "hostname:work-laptop"]
path = ~/.gitconfig.work
[includeIf "hostname:home-pc"]
path = ~/.gitconfig.home
This allows users to write host-specific configuration without separate branches.
Signed-off-by: monarch <ayushoffinfo17@gmail•com>
---
config.c | 37 +++++++++++++++++++++++++++++++------
1 file changed, 31 insertions(+), 6 deletions(-)
diff --git a/config.c b/config.c
index e0ff35d426..dbc1a2bc75 100644
--- a/config.c
+++ b/config.c
@@ -7,6 +7,7 @@
*/
#include "git-compat-util.h"
+#include <unistd.h>
#include "abspath.h"
#include "date.h"
#include "branch.h"
@@ -391,23 +392,47 @@ static int include_by_remote_url(struct config_include_data *inc,
inc->remote_urls);
}
+static int include_by_hostname(const char *cond, size_t cond_len)
+{
+ char actual_hostname[1024];
+ struct strbuf target_hostname = STRBUF_INIT;
+ int ret = 0;
+
+ // Make sure the call to gethostname is correct and its return value is checked.
+ if (gethostname(actual_hostname, sizeof(actual_hostname)) != 0)
+ return 0; // If it fails, the condition is false.
+
+ strbuf_add(&target_hostname, cond, cond_len);
+
+ // The core of the logic: strcmp returns 0 when strings are equal.
+ if (strcmp(actual_hostname, target_hostname.buf) == 0)
+ ret = 1; // Success, the hostnames match!
+
+ strbuf_release(&target_hostname);
+ return ret;
+}
+
static int include_condition_is_true(const struct key_value_info *kvi,
- struct config_include_data *inc,
- const char *cond, size_t cond_len)
+ struct config_include_data *inc,
+ const char *cond, size_t cond_len)
{
- const struct config_options *opts = inc->opts;
+const struct config_options *opts = inc->opts;
+
+
if (skip_prefix_mem(cond, cond_len, "gitdir:", &cond, &cond_len))
return include_by_gitdir(kvi, opts, cond, cond_len, 0);
else if (skip_prefix_mem(cond, cond_len, "gitdir/i:", &cond, &cond_len))
return include_by_gitdir(kvi, opts, cond, cond_len, 1);
- else if (skip_prefix_mem(cond, cond_len, "onbranch:", &cond, &cond_len))
+ else if (skip_prefix_mem(cond, cond_len, "onbranch:", &cond, cond_len))
return include_by_branch(inc, cond, cond_len);
else if (skip_prefix_mem(cond, cond_len, "hasconfig:remote.*.url:", &cond,
- &cond_len))
+ &cond_len))
return include_by_remote_url(inc, cond, cond_len);
+ else if (skip_prefix_mem(cond, cond_len, "hostname:", &cond, &cond_len))
+ return include_by_hostname(cond, cond_len);
- /* unknown conditionals are always false */
+/* unknown conditionals are always false */
return 0;
}
--
2.43.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] config: add "hostname" condition to includeIf
2025-08-22 8:49 monarch
@ 2025-08-27 19:23 ` Ayush Sharma
2025-08-27 20:54 ` Eric Sunshine
0 siblings, 1 reply; 6+ messages in thread
From: Ayush Sharma @ 2025-08-27 19:23 UTC (permalink / raw)
To: git
Hi,
Just a gentle ping to see if there is any feedback on this patch.
Thanks,
Ayush Sharma
On Fri, Aug 22, 2025 at 2:19 PM monarch <ayushoffinfo17@gmail•com> wrote:
>
> Teach "includeIf" to include configuration based on the machine's hostname,
> as returned by gethostname(2).
>
> Example:
>
> [includeIf "hostname:work-laptop"]
> path = ~/.gitconfig.work
>
> [includeIf "hostname:home-pc"]
> path = ~/.gitconfig.home
>
> This allows users to write host-specific configuration without separate branches.
>
> Signed-off-by: monarch <ayushoffinfo17@gmail•com>
> ---
> config.c | 37 +++++++++++++++++++++++++++++++------
> 1 file changed, 31 insertions(+), 6 deletions(-)
>
> diff --git a/config.c b/config.c
> index e0ff35d426..dbc1a2bc75 100644
> --- a/config.c
> +++ b/config.c
> @@ -7,6 +7,7 @@
> */
>
> #include "git-compat-util.h"
> +#include <unistd.h>
> #include "abspath.h"
> #include "date.h"
> #include "branch.h"
> @@ -391,23 +392,47 @@ static int include_by_remote_url(struct config_include_data *inc,
> inc->remote_urls);
> }
>
> +static int include_by_hostname(const char *cond, size_t cond_len)
> +{
> + char actual_hostname[1024];
> + struct strbuf target_hostname = STRBUF_INIT;
> + int ret = 0;
> +
> + // Make sure the call to gethostname is correct and its return value is checked.
> + if (gethostname(actual_hostname, sizeof(actual_hostname)) != 0)
> + return 0; // If it fails, the condition is false.
> +
> + strbuf_add(&target_hostname, cond, cond_len);
> +
> + // The core of the logic: strcmp returns 0 when strings are equal.
> + if (strcmp(actual_hostname, target_hostname.buf) == 0)
> + ret = 1; // Success, the hostnames match!
> +
> + strbuf_release(&target_hostname);
> + return ret;
> +}
> +
> static int include_condition_is_true(const struct key_value_info *kvi,
> - struct config_include_data *inc,
> - const char *cond, size_t cond_len)
> + struct config_include_data *inc,
> + const char *cond, size_t cond_len)
> {
> - const struct config_options *opts = inc->opts;
> +const struct config_options *opts = inc->opts;
> +
> +
>
> if (skip_prefix_mem(cond, cond_len, "gitdir:", &cond, &cond_len))
> return include_by_gitdir(kvi, opts, cond, cond_len, 0);
> else if (skip_prefix_mem(cond, cond_len, "gitdir/i:", &cond, &cond_len))
> return include_by_gitdir(kvi, opts, cond, cond_len, 1);
> - else if (skip_prefix_mem(cond, cond_len, "onbranch:", &cond, &cond_len))
> + else if (skip_prefix_mem(cond, cond_len, "onbranch:", &cond, cond_len))
> return include_by_branch(inc, cond, cond_len);
> else if (skip_prefix_mem(cond, cond_len, "hasconfig:remote.*.url:", &cond,
> - &cond_len))
> + &cond_len))
> return include_by_remote_url(inc, cond, cond_len);
> + else if (skip_prefix_mem(cond, cond_len, "hostname:", &cond, &cond_len))
> + return include_by_hostname(cond, cond_len);
>
> - /* unknown conditionals are always false */
> +/* unknown conditionals are always false */
> return 0;
> }
>
> --
> 2.43.0
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] config: add "hostname" condition to includeIf
2025-08-27 19:23 ` Ayush Sharma
@ 2025-08-27 20:54 ` Eric Sunshine
0 siblings, 0 replies; 6+ messages in thread
From: Eric Sunshine @ 2025-08-27 20:54 UTC (permalink / raw)
To: Ayush Sharma; +Cc: git
On Wed, Aug 27, 2025 at 9:53 AM Ayush Sharma <ayushoffinfo17@gmail•com> wrote:
> On Fri, Aug 22, 2025 at 2:19 PM monarch <ayushoffinfo17@gmail•com> wrote:
> > Teach "includeIf" to include configuration based on the machine's hostname,
> > as returned by gethostname(2).
> >
> > Example:
> > [includeIf "hostname:work-laptop"]
> > path = ~/.gitconfig.work
> > [includeIf "hostname:home-pc"]
> > path = ~/.gitconfig.home
> >
> > This allows users to write host-specific configuration without separate branches.
> >
> > Signed-off-by: monarch <ayushoffinfo17@gmail•com>
> > ---
> > +static int include_by_hostname(const char *cond, size_t cond_len)
> > +{
> > + char actual_hostname[1024];
> > + struct strbuf target_hostname = STRBUF_INIT;
> > + int ret = 0;
> > +
> > + // Make sure the call to gethostname is correct and its return value is checked.
> > + if (gethostname(actual_hostname, sizeof(actual_hostname)) != 0)
> > + return 0; // If it fails, the condition is false.
> > +
> > + strbuf_add(&target_hostname, cond, cond_len);
> > +
> > + // The core of the logic: strcmp returns 0 when strings are equal.
> > + if (strcmp(actual_hostname, target_hostname.buf) == 0)
> > + ret = 1; // Success, the hostnames match!
> > +
> > + strbuf_release(&target_hostname);
> > + return ret;
> > +}
>
> Just a gentle ping to see if there is any feedback on this patch.
You can increase the likelihood of feedback by:
* Studying the related email thread pointed out by Junio in his
response[1] to your initial inquiry, and taking all the open
discussion points into consideration and providing answers for them in
your proposed submission. (For instance, one of the open discussion
points[2] was how a user would know the exact hostname to use with
`includeIf [hostname "..."]`; a solution needs to be provided in order
to move forward with the proposal.)
* Including with your patch the necessary documentation update (so
users will be able to discover this new capability), as well as new
tests.
* Studying Documentation/CodingGuidelines (for instance, this project
uses `/*...*/` comments, not `//`), and
Documentation/SubmittingPatches (for instance, avoid changes, such as
inserting unnecessary blank lines or arbitrarily reformatting code,
unrelated to the purpose of your patch; use your proper name in the
Signed-off-by: footer).
* Consult the Git source code to see whether there is a better way to
obtain the hostname than rolling your own (for instance, don't fall
prey to gethostname() potentially omitting the terminating NUL from
the buffer; instead use xgethostname() from Git's wrapper.c).
[1]: https://lore.kernel.org/git/xmqqqzx8k258.fsf@gitster.g/
[2]: https://lore.kernel.org/git/CAPig+cT4fpX7Kczu0+H5TZnmpVqqq0h8nBafj4UqDs7Xv2Nf4A@mail.gmail.com/
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2025-08-27 20:54 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-22 8:22 [PATCH] config: add "hostname" condition to includeIf monarch
2025-08-22 8:22 ` [PATCH] Start 2.52 cycle, the first batch monarch
-- strict thread matches above, loose matches on Subject: below --
2025-08-22 8:35 [PATCH] config: add "hostname" condition to includeIf monarch
2025-08-22 8:49 monarch
2025-08-27 19:23 ` Ayush Sharma
2025-08-27 20:54 ` Eric Sunshine
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox