Jeff King <p...@peff.net> writes:

> 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;

We do this every time during the parsing?

Hmph, if you had "include.repo:/home/junio/frotz/.path" and
"include.repo:/srv/project/git.git/.path" in your ~/.gitconfig,
then a single regexp that is lazily prepared once will not cut it,
so I guess that you cannot avoid it.

Unlike "git init|clone --profile=foo" that requires you to be
explicit about your profile upon invocation, this mechanism is much
easier to use by having include.<magic>.path in some global
configuration, and the existing precedence rule makes it perfect.
By starting /etc/gitconfig and/or your $HOME/.gitconfig with series
of include.<magic>.path, you can have the default definitions
included from these magic include to take effect before anything
else, and settings from other configuration files can override it.
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to