{"thread":{"id":"135","subject":"[PATCH 8/8] update-cache.c: add INDEX_FILE_DIRECTORY support","startedAt":"2005-04-19T09:09:39Z","lastAt":"2005-04-19T09:09:39Z","messageCount":1,"participants":["Zach Welch"],"isPatch":true,"patchVersion":1,"patchTotal":8},"messages":[{"id":"803","messageId":"mailbox-23311-1113901779-737677@spoon","threadId":"135","inReplyTo":null,"subject":"[PATCH 8/8] update-cache.c: add INDEX_FILE_DIRECTORY support","fromName":"Zach Welch","fromEmail":"zw@superlucidity.net","sentAt":"2005-04-19T09:09:39Z","receivedAt":"2005-04-19T09:09:39Z","isPatch":true,"sender":{"key":"zw@superlucidity.net","avatar":null},"body":"This patch give update-cache the ability for the index directory to be \noverridden by the INDEX_FILE_DIRECTORY environment variable.\n\nThis patch applies on top of:\n        [PATCH 0/8] init-db.c cleanup, add INDEX_FILE_DIRECTORY support\n        [PATCH 1/8] init-db.c: [RESEND] remove redundant getenv call\n        [PATCH 2/8] init-db.c: [RESEND] make init-db work with common objects\n        [PATCH 3/8] init-db.c: refactor directory creation\n        [PATCH 4/8] init-db.c: add INDEX_FILE_DIRECTORY support\n        [PATCH 5/8] init-db.c: refactor mkdir logic\n        [PATCH 6/8] read-cache.c: add INDEX_FILE_DIRECTORY support\n        [PATCH 7/8] read-tree.c: add INDEX_FILE_DIRECTORY support\n update-cache.c |   33 ++++++++++++++++++++++++---------\n 1 files changed, 24 insertions(+), 9 deletions(-)\nSigned-Off-By: Zach Welch <zw@superlucidity.net>\n\n\nupdate-cache.c: 0d16b36d7d074e9f0a2811a40e16e9823a628ec9\n--- a/update-cache.c\n+++ b/update-cache.c\n@@ -270,25 +270,37 @@ static int add_cacheinfo(char *arg1, cha\n \treturn add_cache_entry(ce, allow_add);\n }\n \n-static int remove_lock = 0;\n+static char *index_lock = NULL;\n \n static void remove_lock_file(void)\n {\n-\tif (remove_lock)\n-\t\tunlink(\".git/index.lock\");\n+\tif (index_lock)\n+\t\tunlink(index_lock);\n }\n \n int main(int argc, char **argv)\n {\n-\tint i, newfd, entries;\n+\tint i, newfd, entries, len;\n \tint allow_options = 1;\n+\tchar *index_file, *index_path;\n \n-\tnewfd = open(\".git/index.lock\", O_RDWR | O_CREAT | O_EXCL, 0600);\n+\tindex_path = getenv(INDEX_ENVIRONMENT);\n+\tif (!index_path)\n+\t\tindex_path = DEFAULT_INDEX_ENVIRONMENT;\n+\n+\tlen = strlen(index_path);\n+\tindex_file = malloc(len + 7);\n+\tif (!index_file) error(\"out of memory\");\n+\tsprintf(index_file, \"%s/index\", index_path);\n+\n+\tindex_lock = malloc(len + 12);\n+\tif (!index_lock) error(\"out of memory\");\n+\tsprintf(index_lock, \"%s/index.lock\", index_path);\n+\n+\tnewfd = open(index_lock, O_RDWR | O_CREAT | O_EXCL, 0600);\n \tif (newfd < 0)\n \t\tdie(\"unable to create new cachefile\");\n-\n \tatexit(remove_lock_file);\n-\tremove_lock = 1;\n \n \tentries = read_cache();\n \tif (entries < 0)\n@@ -330,9 +342,12 @@ int main(int argc, char **argv)\n \t\t\tdie(\"Unable to add %s to database\", path);\n \t}\n \tif (write_cache(newfd, active_cache, active_nr) ||\n-\t    rename(\".git/index.lock\", \".git/index\"))\n+\t    rename(index_lock, index_file))\n \t\tdie(\"Unable to write new cachefile\");\n \n-\tremove_lock = 0;\n+\tfree(index_file);\n+\tfree(index_lock);\n+\tindex_lock = NULL;\n+\n \treturn 0;\n }\n"}]}