@matheusbsbs / matheus-bagliano / commits / d7ac12b25d
Fork 0

Add set_git_dir() function

With the function set_git_dir() you can reset the path that will be used for git_path(), git_dir() and friends. The responsibility to close files and throw away information from the old git_dir lies with the caller. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Johannes Schindelin committed Aug 1, 2007 at 01:29 UTC d7ac12b25d375d32372b13f74e90425ca21d5dc1
2 files changed +9
cache.h
+1
@@ -214,6 +214,7 @@ extern char *get_object_directory(void);
214 extern char *get_refs_directory(void);
215 extern char *get_index_file(void);
216 extern char *get_graft_file(void);
217 +extern int set_git_dir(const char *path);
218
219 #define ALTERNATE_DB_ENVIRONMENT "GIT_ALTERNATE_OBJECT_DIRECTORIES"
220
environment.c
+8
@@ -107,3 +107,11 @@ char *get_graft_file(void)
107 setup_git_env();
108 return git_graft_file;
109 }
110 +
111 +int set_git_dir(const char *path)
112 +{
113 + if (setenv(GIT_DIR_ENVIRONMENT, path, 1))
114 + return error("Could not set GIT_DIR to '%s'", path);
115 + setup_git_env();
116 + return 0;
117 +}