From: Jeff King <peff@peff.net>
To: Andrew Ardill <andrew.ardill@gmail.com>
Cc: Junio C Hamano <gitster@pobox.com>,
Michael Haggerty <mhagger@alum.mit.edu>,
Jonathan Nieder <jrnieder@gmail.com>,
Thorsten Glaser <tg@mirbsd.de>,
"git@vger.kernel.org" <git@vger.kernel.org>,
Matthieu Moy <Matthieu.Moy@imag.fr>
Subject: Re: git should not use a default user.email config value
Date: Mon, 12 Aug 2013 08:39:21 -0400 [thread overview]
Message-ID: <20130812123921.GA16088@sigill.intra.peff.net> (raw)
In-Reply-To: <CAH5451nHfOaBzFzkrGvw+TyRj==cVpKF_QdXsTxnn5tTr1c0dw@mail.gmail.com>
On Mon, Aug 12, 2013 at 09:52:45PM +1000, Andrew Ardill wrote:
> On 11 August 2013 02:58, Junio C Hamano <gitster@pobox.com> wrote:
> > Perhaps we need a lighter-weight mechanism
> >
> > git init --profile=open
> > git clone --profile=open git://git.kernel.org/git.git
>
> This is something I would definitely use.
>
> All of my work git directories are in a separate folder to my other
> git directories, and as such it would be extremely convenient if every
> repository under that folder defaulted to the same profile. That may
> be asking for too much though!
We could do something like the patch below, which allows:
$ git config --global include./magic/.path .gitconfig-magic
to read ~/.gitconfig-magic only when we are in a repository with a
directory component "/magic/".
I can see how such a thing might be useful, even though I do not have a
use for that much flexibility myself. I find myself doing this trick for
things like editor settings, but not for git config. So do not count
this necessarily as a vote for doing this; it was a fun exercise for me
that others might find useful.
Comparing this against a "profile" type of solution:
1. This handles only config, not full templates (so no custom hooks;
however, we could provide a level of indirection for hooks inside
the config).
2. Unlike a profile that is used during repository init, this is
resolved at runtime, so it keeps up to date as you change
~/.gitconfig-magic.
---
diff --git a/config.c b/config.c
index e13a7b6..a31dc85 100644
--- a/config.c
+++ b/config.c
@@ -119,10 +119,45 @@ int git_config_include(const char *var, const char *value, void *data)
return ret;
}
+static NORETURN void die_bad_regex(int err, regex_t *re)
+{
+ char errbuf[1024];
+ regerror(err, re, errbuf, sizeof(errbuf));
+ if (cf && cf->name)
+ die("bad regex (at %s:%d): %s", cf->name, cf->linenr, errbuf);
+ else
+ die("bad regex: %s", errbuf);
+}
+
+static int match_repo_path(const char *re_str)
+{
+ regex_t re;
+ int ret;
+ const char *repo_path;
+
+ ret = regcomp(&re, re_str, REG_EXTENDED);
+ if (ret)
+ die_bad_regex(ret, &re);
+
+ repo_path = absolute_path(get_git_dir());
+ ret = regexec(&re, repo_path, 0, NULL, 0);
+ regfree(&re);
+ return !ret;
+}
+
+static int match_repo_path_mem(const char *re_buf, int len)
+{
+ char *re_str = xmemdupz(re_buf, len);
+ int ret = match_repo_path(re_str);
+ free(re_str);
+ return ret;
+}
+
int git_config_include(const char *var, const char *value, void *data)
{
struct config_include_data *inc = data;
- const char *type;
+ const char *match, *type;
+ int match_len;
int ret;
/*
@@ -133,8 +168,9 @@ int git_config_include(const char *var, const char *value, void *data)
if (ret < 0)
return ret;
- type = skip_prefix(var, "include.");
- if (!type)
+ if (parse_config_key(var, "include", &match, &match_len, &type))
+ return ret;
+ if (match && !match_repo_path_mem(match, match_len))
return ret;
if (!strcmp(type, "path"))
next prev parent reply other threads:[~2013-08-12 12:39 UTC|newest]
Thread overview: 46+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20130809134236.28143.75775.reportbug@tglase.lan.tarent.de>
2013-08-09 19:42 ` git should not use a default user.email config value Jonathan Nieder
2013-08-09 20:00 ` Thorsten Glaser
2013-08-09 20:30 ` Felipe Contreras
2013-08-13 8:29 ` Matthieu Moy
2013-08-09 22:37 ` Jeff King
2013-08-09 23:06 ` Junio C Hamano
2013-08-10 6:17 ` Jeff King
2013-08-10 6:40 ` Jonathan Nieder
2013-08-10 6:52 ` Jeff King
2013-08-10 7:03 ` Jonathan Nieder
2013-08-10 7:14 ` Jeff King
2013-08-09 23:19 ` Jonathan Nieder
2013-08-10 6:47 ` Jeff King
2013-08-10 9:59 ` Michael Haggerty
2013-08-10 10:28 ` Jeff King
2013-08-10 11:42 ` Michael Haggerty
2013-08-10 12:06 ` Thorsten Glaser
2013-08-10 12:34 ` Andreas Schwab
2013-08-12 12:51 ` Greg Troxel
2013-08-10 16:58 ` Junio C Hamano
2013-08-12 11:52 ` Andrew Ardill
2013-08-12 12:39 ` Jeff King [this message]
2013-08-12 12:54 ` Michael Haggerty
2013-08-12 15:49 ` Jeff King
2013-08-12 13:01 ` Andrew Ardill
2013-08-12 15:45 ` Jeff King
2013-08-13 11:05 ` Andrew Ardill
2013-08-13 11:46 ` Jeff King
2013-08-13 12:05 ` Jeff King
2013-08-13 12:52 ` Andrew Ardill
2013-08-13 15:53 ` Jeff King
2013-08-13 16:33 ` Junio C Hamano
2013-08-14 7:28 ` Matthieu Moy
2013-08-14 7:40 ` Jeff King
2013-08-14 8:37 ` Matthieu Moy
2013-08-14 14:00 ` Junio C Hamano
2013-08-14 14:07 ` Matthieu Moy
2013-08-14 14:08 ` conditional config syntax Jeff King
2013-08-14 15:41 ` Junio C Hamano
2013-08-14 7:09 ` git should not use a default user.email config value Michael Haggerty
2013-08-14 7:31 ` Jeff King
2013-08-13 16:31 ` Junio C Hamano
2013-08-13 8:08 ` Matthieu Moy
2013-08-11 0:06 ` Aaron Schrab
2013-08-13 8:24 ` Matthieu Moy
2013-08-13 8:39 ` Thorsten Glaser
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=20130812123921.GA16088@sigill.intra.peff.net \
--to=peff@peff.net \
--cc=Matthieu.Moy@imag.fr \
--cc=andrew.ardill@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=jrnieder@gmail.com \
--cc=mhagger@alum.mit.edu \
--cc=tg@mirbsd.de \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).