{"thread":{"id":"31194","subject":"[PATCH] read_index_from: remove bogus errno assignments","startedAt":"2012-08-06T11:27:09Z","lastAt":"2012-08-06T17:03:37Z","messageCount":2,"participants":["Nguyễn Thái Ngọc Duy","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"196540","messageId":"1344252429-7377-1-git-send-email-pclouds@gmail.com","threadId":"31194","inReplyTo":null,"subject":"[PATCH] read_index_from: remove bogus errno assignments","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2012-08-06T11:27:09Z","receivedAt":"2012-08-06T11:27:09Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"These assignments comes from the very first commit e83c516 (Initial\nrevision of \"git\", the information manager from hell - 2005-04-07).\nBack then we did not die() when errors happened so correct errno was\nrequired.\n\nSince 5d1a5c0 ([PATCH] Better error reporting for \"git status\" -\n2005-10-01), read_index_from() learned to die rather than just return\n-1 and these assignments became irrelevant. Remove them.\n\nWhile at it, move die_errno() next to xmmap() call because it's the\nmmap's error code that we care about. Otherwise if close(fd); fails,\nit could overwrite mmap's errno.\n\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n I saw the last hunk in this patch from 01/16 in Thomas's index v5\n series. But it looks more like an independent change. Thomas moved\n read_index_from code so this patch will cause conflicts with his\n series. It's a good change though, I think.\n\n read-cache.c |    6 +-----\n 1 files changed, 1 insertions(+), 5 deletions(-)\n\ndiff --git a/read-cache.c b/read-cache.c\nindex 2f8159f..76513cd 100644\n--- a/read-cache.c\n+++ b/read-cache.c\n@@ -1414,11 +1414,9 @@ int read_index_from(struct index_state *istate, const char *path)\n \tsize_t mmap_size;\n \tstruct strbuf previous_name_buf = STRBUF_INIT, *previous_name;\n \n-\terrno = EBUSY;\n \tif (istate->initialized)\n \t\treturn istate->cache_nr;\n \n-\terrno = ENOENT;\n \tistate->timestamp.sec = 0;\n \tistate->timestamp.nsec = 0;\n \tfd = open(path, O_RDONLY);\n@@ -1431,15 +1429,14 @@ int read_index_from(struct index_state *istate, const char *path)\n \tif (fstat(fd, &st))\n \t\tdie_errno(\"cannot stat the open index\");\n \n-\terrno = EINVAL;\n \tmmap_size = xsize_t(st.st_size);\n \tif (mmap_size < sizeof(struct cache_header) + 20)\n \t\tdie(\"index file smaller than expected\");\n \n \tmmap = xmmap(NULL, mmap_size, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0);\n-\tclose(fd);\n \tif (mmap == MAP_FAILED)\n \t\tdie_errno(\"unable to map index file\");\n+\tclose(fd);\n \n \thdr = mmap;\n \tif (verify_hdr(hdr, mmap_size) < 0)\n@@ -1495,7 +1492,6 @@ int read_index_from(struct index_state *istate, const char *path)\n \n unmap:\n \tmunmap(mmap, mmap_size);\n-\terrno = EINVAL;\n \tdie(\"index file corrupt\");\n }\n \n-- \n1.7.8\n"},{"id":"196547","messageId":"7vsjc0ymty.fsf@alter.siamese.dyndns.org","threadId":"31194","inReplyTo":"1344252429-7377-1-git-send-email-pclouds@gmail.com","subject":"Re: [PATCH] read_index_from: remove bogus errno assignments","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2012-08-06T17:03:37Z","receivedAt":"2012-08-06T17:03:37Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Nguyễn Thái Ngọc Duy <pclouds@gmail.com> writes:\n\n> While at it, move die_errno() next to xmmap() call because it's the\n> mmap's error code that we care about. Otherwise if close(fd); fails,\n> it could overwrite mmap's errno.\n\nMakes sense and is a sensible fix.\n\nThanks.\n"}]}