read-cache.c: Re-read index if index file changed
"Thomas Gummerer" <[email protected]> schrieb im Newsbeitrag news:<[email protected]>...
Quoted 16 lines
Add the possibility of re-reading the index file, if it changed while reading.
The index file might change during the read, causing outdated information to be displayed. We check if the index file changed by using its stat data as heuristic.
Signed-off-by Thomas Gummerer <[email protected]>--- read-cache.c | 87 +++++++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 60 insertions(+), 27 deletions(-)read-cache.c +0
-0
...
Quoted 57 lines
read-cache.c +26
-22@@ -1186,38 +1209,48 @@ int read_index_from(struct index_state *istate, const char *path) errno =ENOENT ; istate->timestamp.sec =0 ; istate->timestamp.nsec =0 ; - fd =open (path,O_RDONLY ); -if (fd <0 ) { -if (errno ==ENOENT ) -return 0 ; -die_errno ("index file open failed" ); - } + do { + err = 0; + fd = open(path, O_RDONLY); + if (fd < 0) { + if (errno == ENOENT) + return 0; + die_errno("index file open failed"); + } -if (fstat (fd, &st)) -die_errno ("cannot stat the open index" ); + if (fstat(fd, &st_old)) + die_errno("cannot stat the open index"); - errno =EINVAL ; - mmap_size =xsize_t (st.st_size); - mmap =xmmap (NULL , mmap_size,PROT_READ |PROT_WRITE ,MAP_PRIVATE , fd,0 ); -close (fd); -if (mmap ==MAP_FAILED ) -die_errno ("unable to map index file" ); + errno = EINVAL; + mmap_size = xsize_t(st_old.st_size); + mmap = xmmap(NULL, mmap_size, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0); + close(fd); + if (mmap == MAP_FAILED) + die_errno("unable to map index file"); - hdr = mmap; -if (verify_hdr_version (istate, hdr, mmap_size) <0 ) - goto unmap; + hdr = mmap; + if (verify_hdr_version(istate, hdr, mmap_size) < 0) + err = 1; -if (istate->ops->verify_hdr (mmap, mmap_size) <0 ) - goto unmap; + if (istate->ops->verify_hdr(mmap, mmap_size) < 0) + err = 1; - istate->ops->read_index (istate, mmap, mmap_size); - istate->timestamp.sec = st.st_mtime; - istate->timestamp.nsec =ST_MTIME_NSEC (st); + if (istate->ops->read_index(istate, mmap, mmap_size) < 0) + err = 1; + istate->timestamp.sec = st_old.st_mtime; + istate->timestamp.nsec = ST_MTIME_NSEC(st_old); + if (lstat(path, &st_new))
read-cache.c int read_index_from(struct index_state *istate, const char *path) · line 1250
Quoted 10 lines
read-cache.c +7
-2+die_errno ("cannot stat the open index" ); -munmap (mmap, mmap_size); -return istate->cache_nr; +munmap (mmap, mmap_size); + +if (!index_changed (st_old, st_new) && !err) +return istate->cache_nr; + +usleep (10 *1000 );
usleep() is not available to anybody, e.g. it is not in HP NonStop (not in every case at least)
Bye, Jojo
Quoted 8 lines · Joachim Schmitz
"Thomas Gummerer" <[email protected]> schrieb im Newsbeitrag news:<[email protected]>...
Review
Quoted 2 lines
[...]
(quoted diff) +1
-0+ usleep(10*1000);
usleep()is not available to anybody, e.g. it is not in HP NonStop (not in every case at least)Bye, Jojo
Thanks for noticing, will be fixed in the re-roll.
Quoted 9 lines
From: Thomas Gummerer [mailto:[email protected]]
Sent: Monday, August 27, 2012 11:40 AM
To: Joachim Schmitz
Cc: [email protected]
Subject: Re: [PATCH/RFC v4 02/13]read-cache.c: Re-read index if index file changedQuoted 1 line · Joachim Schmitz
"Thomas Gummerer" <[email protected]> schrieb im Newsbeitrag news:<1345111129-6925-3-git-send-email-
Quoted 8 lines
Quoted 7 lines
Review
Quoted 2 lines
[...]
(quoted diff) +1
-0+ usleep(10*1000);
usleep()is not available to anybody, e.g. it is not in HP NonStop (not in every case at least)Bye, Jojo
Thanks for noticing, will be fixed in the re-roll.
Instead of
usleep(10*1000);
You could use
poll(NULL, 0, 10);
instead, similar to what help.c is doing
This may need a fix in compat/win32/poll.c though:
compat/win32/poll.c +1 -1
@@ -350,7 +350,7 @@ poll (struct pollfd *pfd, nfds_t nfd, int timeout)/* EFAULT is not necessary to implement, but let's do it in the simplest case. */ -if (!pfd) +if (!pfd && nfd) { errno =EFAULT ;return -1 ;
That fix would be needed anyhow...
Bye, Jojo