Introduce is_bare_repository() and core.bare configuration variable
This removes the old is_bare_git_dir(const char *) to ask if a directory, if it is a GIT_DIR, is a bare repository, and replaces it with is_bare_repository(void *). The function looks at core.bare configuration variable if exists but uses the old heuristics: if it is ".git" or ends with "/.git", then it does not look like a bare repository, otherwise it does. Signed-off-by: Junio C Hamano <junkio@cox.net>
Junio C Hamano committed
Jan 7, 2007 at 02:00 UTC
7d1864ce67d83485cf5cbc8c90fc170ee884ef16
5 files changed
+21
-6
builtin-init-db.c
+6
-2
@@ -252,9 +252,13 @@ static int create_default_files(const char *git_dir, const char *template_path)
252
}
253
git_config_set("core.filemode", filemode ? "true" : "false");
254
255
- /* Enable logAllRefUpdates if a working tree is attached */
256
- if (!is_bare_git_dir(git_dir))
255
+ if (is_bare_repository()) {
256
+ git_config_set("core.bare", "true");
257
+ }
258
+ else {
259
+ git_config_set("core.bare", "false");
260
git_config_set("core.logallrefupdates", "true");
261
+ }
262
return reinit;
263
}
264
cache.h
+2
-1
@@ -127,7 +127,8 @@ extern int cache_errno;
127
#define CONFIG_LOCAL_ENVIRONMENT "GIT_CONFIG_LOCAL"
128
#define EXEC_PATH_ENVIRONMENT "GIT_EXEC_PATH"
129
130
-extern int is_bare_git_dir(const char *dir);
130
+extern int is_bare_repository_cfg;
131
+extern int is_bare_repository(void);
132
extern const char *get_git_dir(void);
133
extern char *get_object_directory(void);
134
extern char *get_refs_directory(void);
config.c
+5
@@ -269,6 +269,11 @@ int git_default_config(const char *var, const char *value)
269
return 0;
270
}
271
272
+ if (!strcmp(var, "core.bare")) {
273
+ is_bare_repository_cfg = git_config_bool(var, value);
274
+ return 0;
275
+ }
276
+
277
if (!strcmp(var, "core.ignorestat")) {
278
assume_unchanged = git_config_bool(var, value);
279
return 0;
environment.c
+7
-2
@@ -15,6 +15,7 @@ int use_legacy_headers = 1;
15
int trust_executable_bit = 1;
16
int assume_unchanged;
17
int prefer_symlink_refs;
18
+int is_bare_repository_cfg = -1; /* unspecified */
19
int log_all_ref_updates = -1; /* unspecified */
20
int warn_ambiguous_refs = 1;
21
int repository_format_version;
@@ -53,9 +54,13 @@ static void setup_git_env(void)
54
git_graft_file = xstrdup(git_path("info/grafts"));
55
}
56
56
-int is_bare_git_dir(const char *dir)
57
+int is_bare_repository(void)
58
{
58
- const char *s;
59
+ const char *dir, *s;
60
+ if (0 <= is_bare_repository_cfg)
61
+ return is_bare_repository_cfg;
62
+
63
+ dir = get_git_dir();
64
if (!strcmp(dir, DEFAULT_GIT_DIR_ENVIRONMENT))
65
return 0;
66
s = strrchr(dir, '/');
refs.c
+1
-1
@@ -924,7 +924,7 @@ static int log_ref_write(struct ref_lock *lock,
924
const char *committer;
925
926
if (log_all_ref_updates < 0)
927
- log_all_ref_updates = !is_bare_git_dir(get_git_dir());
927
+ log_all_ref_updates = !is_bare_repository();
928
929
if (log_all_ref_updates &&
930
(!strncmp(lock->ref_name, "refs/heads/", 11) ||