{"thread":{"id":"136","subject":"[PATCH 6/8] read-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":"804","messageId":"mailbox-23311-1113901779-733079@spoon","threadId":"136","inReplyTo":null,"subject":"[PATCH 6/8] read-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 read-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 read-cache.c |   15 +++++++++++++--\n 1 files changed, 13 insertions(+), 2 deletions(-)\nSigned-Off-By: Zach Welch <zw@superlucidity.net>\n\n\nread-cache.c: edaadf3e1c0714735ca8d80301dd644aa0f9cd2a\n--- a/read-cache.c\n+++ b/read-cache.c\n@@ -174,22 +174,33 @@ static int verify_hdr(struct cache_heade\n \n int read_cache(void)\n {\n-\tint fd, i;\n+\tint fd, i, len;\n \tstruct stat st;\n \tunsigned long size, offset;\n \tvoid *map;\n \tstruct cache_header *hdr;\n+\tchar *index_path, *index_file;\n \n \terrno = EBUSY;\n \tif (active_cache)\n \t\treturn error(\"more than one cachefile\");\n \terrno = ENOENT;\n+\n \tsha1_file_directory = getenv(DB_ENVIRONMENT);\n \tif (!sha1_file_directory)\n \t\tsha1_file_directory = DEFAULT_DB_ENVIRONMENT;\n \tif (access(sha1_file_directory, X_OK) < 0)\n \t\treturn error(\"no access to SHA1 file directory\");\n-\tfd = open(\".git/index\", O_RDONLY);\n+\n+\tindex_path = getenv(INDEX_ENVIRONMENT);\n+\tif (!index_path)\n+\t\tindex_path = DEFAULT_INDEX_ENVIRONMENT;\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+\tfd = open(index_file, O_RDONLY);\n \tif (fd < 0)\n \t\treturn (errno == ENOENT) ? 0 : error(\"open failed\");\n \n"}]}