git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* "Racy" GIT
@ 2005-10-24  9:29 Petr Baudis
  2005-10-24 16:34 ` Linus Torvalds
  0 siblings, 1 reply; 2+ messages in thread
From: Petr Baudis @ 2005-10-24  9:29 UTC (permalink / raw)
  To: git

  Hello,

  I've  thought that I might describe the race I've hit the last night
here so that if you meet it too, you will have an idea what is going on
and won't waste your time debugging it, like I did. ;-)

  What did I do:

  echo v1 >file
  cg-add file
  cg-commit -m"v1"

  echo v2 >file
  cg-commit -m"v2"

  Guess what - the second cg-commit didn't commit the new version of the
file. git-diff-index didn't show anything. GIT just didn't care about
the change.

  Obviously, the problem was that the stat information was exactly the
same after the change (it was in a script, so no ctime change, and the
size was the same as well). The solution is to tell git/Cogito about the
change explicitly (in Cogito, you can do that e.g. by calling cg-add on
the file again). This can be obviously very confusing (and dangerous),
but if we want to keep the stat caching, I guess there is no way around
this (except for sub-second ctimes, but that effectively killed the stat
caching on the filesystems which didn't support it).

-- 
				Petr "Pasky" Baudis
Stuff: http://pasky.or.cz/
VI has two modes: the one in which it beeps and the one in which
it doesn't.

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: "Racy" GIT
  2005-10-24  9:29 "Racy" GIT Petr Baudis
@ 2005-10-24 16:34 ` Linus Torvalds
  0 siblings, 0 replies; 2+ messages in thread
From: Linus Torvalds @ 2005-10-24 16:34 UTC (permalink / raw)
  To: Petr Baudis; +Cc: git



On Mon, 24 Oct 2005, Petr Baudis wrote:
> 
>   Guess what - the second cg-commit didn't commit the new version of the
> file. git-diff-index didn't show anything. GIT just didn't care about
> the change.

Yeah. This is why I wanted to use the "tv_nsec" field originally.

As it is, if you change a file within a second so that the length is the 
same (and inode stays the same), the stat cache can't help you.

Now, this will only trigger if you do a git-update-index (either directly 
or like in your example, indirectly though doing a commit that does it) 
and then change it again immediately, so in practice it shouldn't matter. 
Except for scripts.

In scripts, you can avoid this certain ways:

 - add a "sleep 1" (gaah, just joking, but it works)

 - use "git-apply --index" (which updates the index on its own on any 
   files it changes) to apply any patches.

 - use an explicit "git-update-index -- filename"

 - if you actually change the inode number, it should be ok, ie

	sed script < a > b && mv b a

   will change the inode number, and that should trigger the index tests 
   too. NOTE!! This isn't guaranteed, especially if you do it twice (it 
   might re-use the original one)

Note that "git-update-index --refresh" will _not_ work, since it looks if 
it changed. But an explicit filename will force an update if you know it 
changed.

And yes, I guess we should document this in big letters.

(There _are_ actually tricks you can do to make this usually less of an 
issue:

 - if the git-update-cache --refresh finds file where the mtime matches 
   the current date. It sets a flag. At the end, it waits for the next 
   second to roll around before returning.

might work well enough)

		Linus

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2005-10-24 16:34 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-10-24  9:29 "Racy" GIT Petr Baudis
2005-10-24 16:34 ` Linus Torvalds

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).