{"thread":{"id":"5182","subject":"[PATCH 2/2] merge-recur: do not setenv(\"GIT_INDEX_FILE\")","startedAt":"2006-08-09T13:07:31Z","lastAt":"2006-08-09T13:07:31Z","messageCount":1,"participants":["Johannes Schindelin"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"25027","messageId":"Pine.LNX.4.63.0608091507200.1800@wbgn013.biozentrum.uni-wuerzburg.de","threadId":"5182","inReplyTo":null,"subject":"[PATCH 2/2] merge-recur: do not setenv(\"GIT_INDEX_FILE\")","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2006-08-09T13:07:31Z","receivedAt":"2006-08-09T13:07:31Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"\nSince there are no external calls left in merge-recur, we do not need\nto set the environment variable GIT_INDEX_FILE all the time.\n\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n merge-recursive.c |   22 +++++++++-------------\n 1 files changed, 9 insertions(+), 13 deletions(-)\n\ndiff --git a/merge-recursive.c b/merge-recursive.c\nindex b8b0951..7a93dd9 100644\n--- a/merge-recursive.c\n+++ b/merge-recursive.c\n@@ -116,6 +116,7 @@ static void output_commit_title(struct c\n \t}\n }\n \n+static const char *current_index_file = NULL;\n static const char *original_index_file;\n static const char *temporary_index_file;\n static int cache_dirty = 0;\n@@ -124,12 +125,12 @@ static int flush_cache(void)\n {\n \t/* flush temporary index */\n \tstruct lock_file *lock = xcalloc(1, sizeof(struct lock_file));\n-\tint fd = hold_lock_file_for_update(lock, getenv(\"GIT_INDEX_FILE\"));\n+\tint fd = hold_lock_file_for_update(lock, current_index_file);\n \tif (fd < 0)\n \t\tdie(\"could not lock %s\", lock->filename);\n \tif (write_cache(fd, active_cache, active_nr) ||\n \t\t\tclose(fd) || commit_lock_file(lock))\n-\t\tdie (\"unable to write %s\", getenv(\"GIT_INDEX_FILE\"));\n+\t\tdie (\"unable to write %s\", current_index_file);\n \tdiscard_cache();\n \tcache_dirty = 0;\n \treturn 0;\n@@ -137,11 +138,10 @@ static int flush_cache(void)\n \n static void setup_index(int temp)\n {\n-\tconst char *idx = temp ? temporary_index_file: original_index_file;\n+\tcurrent_index_file = temp ? temporary_index_file: original_index_file;\n \tif (cache_dirty)\n \t\tdie(\"fatal: cache changed flush_cache();\");\n \tunlink(temporary_index_file);\n-\tsetenv(\"GIT_INDEX_FILE\", idx, 1);\n \tdiscard_cache();\n }\n \n@@ -174,7 +174,7 @@ static int add_cacheinfo(unsigned int mo\n {\n \tstruct cache_entry *ce;\n \tif (!cache_dirty)\n-\t\tread_cache_from(getenv(\"GIT_INDEX_FILE\"));\n+\t\tread_cache_from(current_index_file);\n \tcache_dirty++;\n \tce = make_cache_entry(mode, sha1 ? sha1 : null_sha1, path, stage, refresh);\n \tif (!ce)\n@@ -223,7 +223,7 @@ static int git_merge_trees(int index_onl\n \tstruct unpack_trees_options opts;\n \n \tif (!cache_dirty) {\n-\t\tread_cache_from(getenv(\"GIT_INDEX_FILE\"));\n+\t\tread_cache_from(current_index_file);\n \t\tcache_dirty = 1;\n \t}\n \n@@ -260,7 +260,7 @@ static struct tree *git_write_tree(void)\n \t\t\t\treturn NULL;\n \t\t}\n \t} else\n-\t\tread_cache_from(getenv(\"GIT_INDEX_FILE\"));\n+\t\tread_cache_from(current_index_file);\n \n \tif (!active_cache_tree)\n \t\tactive_cache_tree = cache_tree();\n@@ -338,7 +338,7 @@ static struct path_list *get_unmerged(vo\n \n \tunmerged->strdup_paths = 1;\n \tif (!cache_dirty) {\n-\t\tread_cache_from(getenv(\"GIT_INDEX_FILE\"));\n+\t\tread_cache_from(current_index_file);\n \t\tcache_dirty++;\n \t}\n \tfor (i = 0; i < active_nr; i++) {\n@@ -468,10 +468,6 @@ static int remove_path(const char *name)\n \treturn ret;\n }\n \n-/*\n- * TODO: once we no longer call external programs, we'd probably be better off\n- * not setting / getting the environment variable GIT_INDEX_FILE all the time.\n- */\n int remove_file(int clean, const char *path)\n {\n \tint update_cache = index_only || clean;\n@@ -479,7 +475,7 @@ int remove_file(int clean, const char *p\n \n \tif (update_cache) {\n \t\tif (!cache_dirty)\n-\t\t\tread_cache_from(getenv(\"GIT_INDEX_FILE\"));\n+\t\t\tread_cache_from(current_index_file);\n \t\tcache_dirty++;\n \t\tif (remove_file_from_cache(path))\n \t\t\treturn -1;\n-- \n1.4.2.rc3.g55597-dirty\n"}]}