git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [RFC] ident: support per-path configs by matching the path against a pattern
@ 2015-07-10  9:36 Sebastian Schuberth
  2015-07-10 15:10 ` Junio C Hamano
  0 siblings, 1 reply; 7+ messages in thread
From: Sebastian Schuberth @ 2015-07-10  9:36 UTC (permalink / raw)
  To: git

Support per-path identities by configuring Git like

    $ git config user.<pattern>.email <email address>

e.g.

    $ git config user.github.email sschuberth+github@gmail.com

In this example, the middle "github" pattern is searched for
case-insensitively in the absolute path name to the current git work tree.
If there is a match the configured email address is used instead of what
otherwise would be the default email address.

Note that repository-local identities still take precedence over global /
system ones even if the pattern configured in the global / system identity
matches the path to the local work tree.

This change avoids the need to use external tools like [1].

TODO: Once the community agrees that this is a feature worth having, add
tests and adjust the docs.

[1] https://github.com/prydonius/karn

Signed-off-by: Sebastian Schuberth <sschuberth@gmail.com>
---
 ident.c | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/ident.c b/ident.c
index 5ff1aad..2429ed8 100644
--- a/ident.c
+++ b/ident.c
@@ -390,7 +390,21 @@ int author_ident_sufficiently_given(void)
 
 int git_ident_config(const char *var, const char *value, void *data)
 {
-	if (!strcmp(var, "user.name")) {
+	/* the caller has already checked that var starts with "user." */
+
+	const char *first_period = strchr(var, '.');
+	const char *last_period = strrchr(var, '.');
+
+	if (first_period < last_period) {
+		++first_period;
+		char *pattern = xstrndup(first_period, last_period - first_period);
+		const char *match = strcasestr(get_git_work_tree(), pattern);
+		free(pattern);
+		if (!match)
+			return 0;
+	}
+
+	if (ends_with(var, ".name")) {
 		if (!value)
 			return config_error_nonbool(var);
 		strbuf_reset(&git_default_name);
@@ -400,7 +414,7 @@ int git_ident_config(const char *var, const char *value, void *data)
 		return 0;
 	}
 
-	if (!strcmp(var, "user.email")) {
+	if (ends_with(var, ".email")) {
 		if (!value)
 			return config_error_nonbool(var);
 		strbuf_reset(&git_default_email);

---
https://github.com/git/git/pull/161

^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2015-07-10 21:07 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-07-10  9:36 [RFC] ident: support per-path configs by matching the path against a pattern Sebastian Schuberth
2015-07-10 15:10 ` Junio C Hamano
2015-07-10 15:43   ` Jeff King
2015-07-10 16:46     ` Jeff King
2015-07-10 20:23       ` Junio C Hamano
2015-07-10 20:58         ` Jeff King
2015-07-10 21:07           ` Junio C Hamano

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).