git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Joachim Schmitz" <jojo@schmitz-digital.de>
To: <t.gummerer@gmail.com>
Cc: <git@vger.kernel.org>
Subject: Re: [PATCH/RFC v4 02/13] read-cache.c: Re-read index if index file changed
Date: Sat, 25 Aug 2012 18:02:39 +0200	[thread overview]
Message-ID: <001d01cd82db$0dc00870$29401950$@schmitz-digital.de> (raw)

"Thomas Gummerer" <t.gummerer@gmail.com> schrieb im Newsbeitrag news:<1345111129-6925-3-git-send-email-t.gummerer@gmail.com>...
> 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 <t.gummerer@gmail.com>
> ---
>  read-cache.c | 87 +++++++++++++++++++++++++++++++++++++++++-------------------
>  1 file changed, 60 insertions(+), 27 deletions(-)
> 
> diff --git a/read-cache.c b/read-cache.c
> index 6a8b4b1..cdd8480 100644
> --- a/read-cache.c
> +++ b/read-cache.c
...
> @@ -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))
> +			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

             reply	other threads:[~2012-08-25 16:03 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-08-25 16:02 Joachim Schmitz [this message]
2012-08-27  9:39 ` [PATCH/RFC v4 02/13] read-cache.c: Re-read index if index file changed Thomas Gummerer
2012-09-07  7:22   ` Joachim Schmitz
  -- strict thread matches above, loose matches on Subject: below --
2012-08-16  9:58 [PATCH/RFC v4 0/13] Introduce index file format version 5 Thomas Gummerer
2012-08-16  9:58 ` [PATCH/RFC v4 02/13] read-cache.c: Re-read index if index file changed Thomas Gummerer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='001d01cd82db$0dc00870$29401950$@schmitz-digital.de' \
    --to=jojo@schmitz-digital.de \
    --cc=git@vger.kernel.org \
    --cc=t.gummerer@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).