{"thread":{"id":"31355","subject":"Re: [PATCH/RFC v4 02/13] read-cache.c: Re-read index if index file changed","startedAt":"2012-08-25T16:02:39Z","lastAt":"2012-09-07T07:22:33Z","messageCount":3,"participants":["Joachim Schmitz","Thomas Gummerer"],"isPatch":true,"patchVersion":4,"patchTotal":13},"messages":[{"id":"197837","messageId":"001d01cd82db$0dc00870$29401950$@schmitz-digital.de","threadId":"31355","inReplyTo":null,"subject":"Re: [PATCH/RFC v4 02/13] read-cache.c: Re-read index if index file changed","fromName":"Joachim Schmitz","fromEmail":"jojo@schmitz-digital.de","sentAt":"2012-08-25T16:02:39Z","receivedAt":"2012-08-25T16:02:39Z","isPatch":true,"sender":{"key":"jojo@schmitz-digital.de","avatar":"https://avatars.githubusercontent.com/u/1786669?v=4"},"body":"\"Thomas Gummerer\" <t.gummerer@gmail.com> schrieb im Newsbeitrag news:<1345111129-6925-3-git-send-email-t.gummerer@gmail.com>...\n> Add the possibility of re-reading the index file, if it changed\n> while reading.\n> \n> The index file might change during the read, causing outdated\n> information to be displayed. We check if the index file changed\n> by using its stat data as heuristic.\n> \n> Signed-off-by: Thomas Gummerer <t.gummerer@gmail.com>\n> ---\n>  read-cache.c | 87 +++++++++++++++++++++++++++++++++++++++++-------------------\n>  1 file changed, 60 insertions(+), 27 deletions(-)\n> \n> diff --git a/read-cache.c b/read-cache.c\n> index 6a8b4b1..cdd8480 100644\n> --- a/read-cache.c\n> +++ b/read-cache.c\n...\n> @@ -1186,38 +1209,48 @@ int read_index_from(struct index_state *istate, const char *path)\n>  \terrno = ENOENT;\n>  \tistate->timestamp.sec = 0;\n>  \tistate->timestamp.nsec = 0;\n> -\tfd = open(path, O_RDONLY);\n> -\tif (fd < 0) {\n> -\t\tif (errno == ENOENT)\n> -\t\t\treturn 0;\n> -\t\tdie_errno(\"index file open failed\");\n> -\t}\n> +\tdo {\n> +\t\terr = 0;\n> +\t\tfd = open(path, O_RDONLY);\n> +\t\tif (fd < 0) {\n> +\t\t\tif (errno == ENOENT)\n> +\t\t\t\treturn 0;\n> +\t\t\tdie_errno(\"index file open failed\");\n> +\t\t}\n>  \n> -\tif (fstat(fd, &st))\n> -\t\tdie_errno(\"cannot stat the open index\");\n> +\t\tif (fstat(fd, &st_old))\n> +\t\t\tdie_errno(\"cannot stat the open index\");\n>  \n> -\terrno = EINVAL;\n> -\tmmap_size = xsize_t(st.st_size);\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> +\t\terrno = EINVAL;\n> +\t\tmmap_size = xsize_t(st_old.st_size);\n> +\t\tmmap = xmmap(NULL, mmap_size, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0);\n> +\t\tclose(fd);\n> +\t\tif (mmap == MAP_FAILED)\n> +\t\t\tdie_errno(\"unable to map index file\");\n>  \n> -\thdr = mmap;\n> -\tif (verify_hdr_version(istate, hdr, mmap_size) < 0)\n> -\t\tgoto unmap;\n> +\t\thdr = mmap;\n> +\t\tif (verify_hdr_version(istate, hdr, mmap_size) < 0)\n> +\t\t\terr = 1;\n>  \n> -\tif (istate->ops->verify_hdr(mmap, mmap_size) < 0)\n> -\t\tgoto unmap;\n> +\t\tif (istate->ops->verify_hdr(mmap, mmap_size) < 0)\n> +\t\t\terr = 1;\n>  \n> -\tistate->ops->read_index(istate, mmap, mmap_size);\n> -\tistate->timestamp.sec = st.st_mtime;\n> -\tistate->timestamp.nsec = ST_MTIME_NSEC(st);\n> +\t\tif (istate->ops->read_index(istate, mmap, mmap_size) < 0)\n> +\t\t\terr = 1;\n> +\t\tistate->timestamp.sec = st_old.st_mtime;\n> +\t\tistate->timestamp.nsec = ST_MTIME_NSEC(st_old);\n> +\t\tif (lstat(path, &st_new))\n> +\t\t\tdie_errno(\"cannot stat the open index\");\n>  \n> -\tmunmap(mmap, mmap_size);\n> -\treturn istate->cache_nr;\n> +\t\tmunmap(mmap, mmap_size);\n> +\n> +\t\tif (!index_changed(st_old, st_new) && !err)\n> +\t\t\treturn istate->cache_nr;\n> +\n> +\t\tusleep(10*1000);\n\n\nusleep() is not available to anybody, e.g. it is not in HP NonStop (not in every case at least)\n\nBye, Jojo\n"},{"id":"197893","messageId":"20120827093930.GC26470@tommy-fedora.surfnet.iacbox","threadId":"31355","inReplyTo":"001d01cd82db$0dc00870$29401950$@schmitz-digital.de","subject":"Re: [PATCH/RFC v4 02/13] read-cache.c: Re-read index if index file changed","fromName":"Thomas Gummerer","fromEmail":"t.gummerer@gmail.com","sentAt":"2012-08-27T09:39:30Z","receivedAt":"2012-08-27T09:39:30Z","isPatch":true,"sender":{"key":"t.gummerer@gmail.com","avatar":"https://avatars.githubusercontent.com/u/191004?v=4"},"body":"On 08/25, Joachim Schmitz wrote:\n> \"Thomas Gummerer\" <t.gummerer@gmail.com> schrieb im Newsbeitrag news:<1345111129-6925-3-git-send-email-t.gummerer@gmail.com>...\n> > [...]\n> > +\t\tusleep(10*1000);\n> \n> usleep() is not available to anybody, e.g. it is not in HP NonStop (not in every case at least)\n> \n> Bye, Jojo\n> \nThanks for noticing, will be fixed in the re-roll.\n"},{"id":"198504","messageId":"000c01cd8cc9$8cd1fea0$a675fbe0$@schmitz-digital.de","threadId":"31355","inReplyTo":"20120827093930.GC26470@tommy-fedora.surfnet.iacbox","subject":"RE: [PATCH/RFC v4 02/13] read-cache.c: Re-read index if index file changed","fromName":"Joachim Schmitz","fromEmail":"jojo@schmitz-digital.de","sentAt":"2012-09-07T07:22:33Z","receivedAt":"2012-09-07T07:22:33Z","isPatch":true,"sender":{"key":"jojo@schmitz-digital.de","avatar":"https://avatars.githubusercontent.com/u/1786669?v=4"},"body":"> From: Thomas Gummerer [mailto:t.gummerer@gmail.com]\n> Sent: Monday, August 27, 2012 11:40 AM\n> To: Joachim Schmitz\n> Cc: git@vger.kernel.org\n> Subject: Re: [PATCH/RFC v4 02/13] read-cache.c: Re-read index if index file changed\n> \n> On 08/25, Joachim Schmitz wrote:\n> > \"Thomas Gummerer\" <t.gummerer@gmail.com> schrieb im Newsbeitrag news:<1345111129-6925-3-git-send-email-\n> t.gummerer@gmail.com>...\n> > > [...]\n> > > +\t\tusleep(10*1000);\n> >\n> > usleep() is not available to anybody, e.g. it is not in HP NonStop (not in every case at least)\n> >\n> > Bye, Jojo\n> >\n> Thanks for noticing, will be fixed in the re-roll.\n\nInstead of\n\nusleep(10*1000);\n\nYou could use\n\npoll(NULL, 0, 10); \n\ninstead, similar to what help.c is doing\n\nThis may need a fix in compat/win32/poll.c though:\n\ndiff --git a/compat/win32/poll.c b/compat/win32/poll.c\n--- a/compat/win32/poll.c\n+++ b/compat/win32/poll.c\n@@ -350,7 +350,7 @@ poll (struct pollfd *pfd, nfds_t nfd, int timeout)\n\n   /* EFAULT is not necessary to implement, but let's do it in the\n      simplest case. */\n-  if (!pfd)\n+  if (!pfd && nfd)\n     {\n       errno = EFAULT;\n       return -1;\n\nThat fix would be needed anyhow...\n\nBye, Jojo\n"}]}