Commit Graph

7 Commits

Author SHA1 Message Date
FUJIWARA Katsunori
8a6898b88d scmutil: add file object wrapper class to check ambiguity at closing
In Mercurial source tree, opening a file in "a"/"a+" mode like below
doesn't specify atomictemp=True for vfs, and this avoids file stat
ambiguity check by atomictempfile.

  - writing changes out in revlog layer uses "a+" mode
  - truncation in repair.strip() uses "a" mode
  - truncation in transaction._playback() uses "a" mode

If steps below occurs at "the same time in sec", all of mtime, ctime
and size are same between (1) and (3).

  1. append data to revlog-style file (and close transaction)
  2. discard appended data by truncation (strip or rollback)
  3. append same size but different data to revlog-style file again

Therefore, cache validation doesn't work after (3) as expected.

This patch adds file object wrapper class checkambigatclosing to check
(and get rid of) ambiguity at closing. It is used by vfs in subsequent
patch.

This is a part of ExactCacheValidationPlan.

    https://www.mercurial-scm.org/wiki/ExactCacheValidationPlan

BTW, checkambigatclosing is tested in test-filecache.py, even though
it doesn't use filecache itself, because filecache assumes that file
stat ambiguity never occurs (and there is no another test-*.py related
to filecache).
2016-09-22 21:51:57 +09:00
Siddharth Agarwal
25418f3155 scmutil.filecache: support watching over multiple files 2013-11-16 13:29:39 -08:00
Siddharth Agarwal
a8599adaa0 test-filecache.py: add markers to the output for each event
Previously it was possible that a different, incorrect set of events might
print out 'creating' the same number of times.
2013-11-16 13:57:35 -08:00
Siddharth Agarwal
7311dfb44a test-filecache.py: make setbeforeget test clearer
'0' and 'None' as outputs tripped me up. Make the distinction between values
set externally and values computed by calling the decorated function clearer.
2013-11-16 14:10:28 -08:00
Idan Kamara
ad6fc4bb63 filecache: create an entry in _filecache when __set__ is called for a missing one
Preserve the invariant that if P is a filecached property on X then
P in X.__dict__ => P in X._filecache.

Previously, it was possible for a filecached property to become out of sync
with the filesystem if it was set before getting it first, since the initial
filecacheentry was created in __get__.

Old behaviour:

  repo.prop = x
  repo.invalidate() # prop has no entry in _filecache, it's not removed
                    # from __dict__
  repo.prop         # returns x like before without checking with the
                    # filesystem

New:

  repo.prop = x     # an empty entry is created in _filecache
  repo.invalidate() # prop is removed from __dict__
  repo.prop         # recreates prop
2012-12-17 15:25:45 +02:00
Idan Kamara
ca54b38975 destroyed: keep the filecache in sync with __dict__ (issue3335) (issue3693) (issue3743)
We need to make sure that if X is in the filecache then it's also in the
filecache owner's __dict__, otherwise it will go out of sync:

repo.X                  # first access to X, records stat info in
                        # filecache and updates __dict__
repo._filecache.clear() # removes X from _filecache but it's still in __dict__
repo.invalidate()       # iterates over _filecache and removes entries
                        # from __dict__, but X isn't in _filecache, so
                        # it's kept in __dict__
repo.X                  # X is fetched from __dict__, bypassing the filecache
2013-01-09 20:37:44 +02:00
Idan Kamara
3b6032fdaf scmutil: introduce filecache
The idea is being able to associate a file with a property, and watch
that file stat info for modifications when we decide it's important for it to
be up-to-date. Once it changes, we recreate the object.

On filesystems that can't uniquely identify a file, we always recreate.

As a consequence, localrepo.invalidate() will become much less expensive in the
case where nothing changed on-disk.
2011-07-09 19:06:59 +03:00