[PATCH RFC 7/8] config: add git_config_norepo

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This function will be needed to read the configuration in git-clone
before the new repository is created.

Signed-off-by: Paolo Bonzini <bonzini@xxxxxxx>
---
 cache.h  |    1 +
 config.c |   37 ++++++++++++++++++++++++++++---------
 2 files changed, 29 insertions(+), 9 deletions(-)

diff --git a/cache.h b/cache.h
index a46bfe6..c349cd1 100644
--- a/cache.h
+++ b/cache.h
@@ -893,6 +893,7 @@ typedef int (*config_fn_t)(const char *, const char *, void *);
 extern int git_tracking_config(const char *, const char *, struct tracking_config *);
 extern int git_default_config(const char *, const char *, void *);
 extern int git_config_from_file(config_fn_t fn, const char *, void *);
+extern int git_config_norepo(config_fn_t fn, void *);
 extern int git_config(config_fn_t fn, void *);
 extern int git_parse_ulong(const char *, unsigned long *);
 extern int git_config_int(const char *, const char *);
diff --git a/config.c b/config.c
index 37d95a4..d50a261 100644
--- a/config.c
+++ b/config.c
@@ -709,19 +709,14 @@ int git_config_global(void)
 	return !git_env_bool("GIT_CONFIG_NOGLOBAL", 0);
 }
 
-int git_config(config_fn_t fn, void *data)
+static int git_config_extra_repo(config_fn_t fn, void *data, int *found)
 {
-	int ret = 0, found = 0;
-	char *repo_config = NULL;
+	int ret = 0;
 	const char *home = NULL;
-
-	/* Setting $GIT_CONFIG makes git read _only_ the given config file. */
-	if (config_exclusive_filename)
-		return git_config_from_file(fn, config_exclusive_filename, data);
 	if (git_config_system() && !access(git_etc_gitconfig(), R_OK)) {
 		ret += git_config_from_file(fn, git_etc_gitconfig(),
 					    data);
-		found += 1;
+		*found += 1;
 	}
 
 	home = getenv("HOME");
@@ -729,11 +724,35 @@ int git_config(config_fn_t fn, void *data)
 		char *user_config = xstrdup(mkpath("%s/.gitconfig", home));
 		if (!access(user_config, R_OK)) {
 			ret += git_config_from_file(fn, user_config, data);
-			found += 1;
+			*found += 1;
 		}
 		free(user_config);
 	}
+	return ret;
+}
+
+int git_config_norepo(config_fn_t fn, void *data)
+{
+	int ret, found = 0;
+
+	/* Setting $GIT_CONFIG makes git read _only_ the given config file. */
+	if (config_exclusive_filename)
+		return git_config_from_file(fn, config_exclusive_filename, data);
+	ret = git_config_extra_repo (fn, data, &found);
+	if (found == 0)
+		return -1;
+	return ret;
+}
 
+int git_config(config_fn_t fn, void *data)
+{
+	int ret, found = 0;
+	char *repo_config;
+
+	/* Setting $GIT_CONFIG makes git read _only_ the given config file. */
+	if (config_exclusive_filename)
+		return git_config_from_file(fn, config_exclusive_filename, data);
+	ret = git_config_extra_repo (fn, data, &found);
 	repo_config = git_pathdup("config");
 	if (!access(repo_config, R_OK)) {
 		ret += git_config_from_file(fn, repo_config, data);
-- 
1.6.2.5

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]