tests/test-filecache.py
author Robert Stanca <robert.stanca7@gmail.com>
Mon, 04 Apr 2016 05:20:40 +0300
changeset 28766 7f7cd44cd6d5
parent 28742 a08c90d622eb
child 28802 b16eacf5347c
permissions -rw-r--r--
py3: use print_function in test-status-inprocess.py
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
28742
a08c90d622eb py3: use print_function in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 28741
diff changeset
     1
from __future__ import absolute_import, print_function
28741
fc5f548393bf py3: use absolute_import in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 26098
diff changeset
     2
import os
fc5f548393bf py3: use absolute_import in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 26098
diff changeset
     3
import subprocess
fc5f548393bf py3: use absolute_import in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 26098
diff changeset
     4
import sys
14928
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
     5
16683
525fdb738975 cleanup: eradicate long lines
Brodie Rao <brodie@sf.io>
parents: 15518
diff changeset
     6
if subprocess.call(['python', '%s/hghave' % os.environ['TESTDIR'],
525fdb738975 cleanup: eradicate long lines
Brodie Rao <brodie@sf.io>
parents: 15518
diff changeset
     7
                    'cacheable']):
14928
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
     8
    sys.exit(80)
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
     9
18313
3e4a944c0d04 destroyed: keep the filecache in sync with __dict__ (issue3335) (issue3693) (issue3743)
Idan Kamara <idankk86@gmail.com>
parents: 16688
diff changeset
    10
from mercurial import util, scmutil, extensions, hg, ui
14928
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
    11
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
    12
filecache = scmutil.filecache
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
    13
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
    14
class fakerepo(object):
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
    15
    def __init__(self):
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
    16
        self._filecache = {}
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
    17
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
    18
    def join(self, p):
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
    19
        return p
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
    20
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
    21
    def sjoin(self, p):
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
    22
        return p
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
    23
20045
b3684fd2ff1a scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents: 20041
diff changeset
    24
    @filecache('x', 'y')
14928
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
    25
    def cached(self):
28742
a08c90d622eb py3: use print_function in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 28741
diff changeset
    26
        print('creating')
20040
ed80cecdfc57 test-filecache.py: make setbeforeget test clearer
Siddharth Agarwal <sid0@fb.com>
parents: 18316
diff changeset
    27
        return 'string from function'
14928
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
    28
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
    29
    def invalidate(self):
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
    30
        for k in self._filecache:
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
    31
            try:
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
    32
                delattr(self, k)
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
    33
            except AttributeError:
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
    34
                pass
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
    35
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
    36
def basic(repo):
28742
a08c90d622eb py3: use print_function in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 28741
diff changeset
    37
    print("* neither file exists")
20041
42deff43460a test-filecache.py: add markers to the output for each event
Siddharth Agarwal <sid0@fb.com>
parents: 20040
diff changeset
    38
    # calls function
14928
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
    39
    repo.cached
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
    40
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
    41
    repo.invalidate()
28742
a08c90d622eb py3: use print_function in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 28741
diff changeset
    42
    print("* neither file still exists")
20041
42deff43460a test-filecache.py: add markers to the output for each event
Siddharth Agarwal <sid0@fb.com>
parents: 20040
diff changeset
    43
    # uses cache
14928
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
    44
    repo.cached
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
    45
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
    46
    # create empty file
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
    47
    f = open('x', 'w')
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
    48
    f.close()
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
    49
    repo.invalidate()
28742
a08c90d622eb py3: use print_function in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 28741
diff changeset
    50
    print("* empty file x created")
14928
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
    51
    # should recreate the object
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
    52
    repo.cached
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
    53
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
    54
    f = open('x', 'w')
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
    55
    f.write('a')
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
    56
    f.close()
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
    57
    repo.invalidate()
28742
a08c90d622eb py3: use print_function in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 28741
diff changeset
    58
    print("* file x changed size")
14928
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
    59
    # should recreate the object
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
    60
    repo.cached
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
    61
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
    62
    repo.invalidate()
28742
a08c90d622eb py3: use print_function in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 28741
diff changeset
    63
    print("* nothing changed with either file")
20041
42deff43460a test-filecache.py: add markers to the output for each event
Siddharth Agarwal <sid0@fb.com>
parents: 20040
diff changeset
    64
    # stats file again, reuses object
14928
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
    65
    repo.cached
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
    66
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
    67
    # atomic replace file, size doesn't change
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
    68
    # hopefully st_mtime doesn't change as well so this doesn't use the cache
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
    69
    # because of inode change
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
    70
    f = scmutil.opener('.')('x', 'w', atomictemp=True)
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
    71
    f.write('b')
15057
774da7121fc9 atomictempfile: make close() consistent with other file-like objects.
Greg Ward <greg@gerg.ca>
parents: 14982
diff changeset
    72
    f.close()
14928
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
    73
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
    74
    repo.invalidate()
28742
a08c90d622eb py3: use print_function in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 28741
diff changeset
    75
    print("* file x changed inode")
14928
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
    76
    repo.cached
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
    77
20045
b3684fd2ff1a scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents: 20041
diff changeset
    78
    # create empty file y
b3684fd2ff1a scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents: 20041
diff changeset
    79
    f = open('y', 'w')
b3684fd2ff1a scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents: 20041
diff changeset
    80
    f.close()
b3684fd2ff1a scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents: 20041
diff changeset
    81
    repo.invalidate()
28742
a08c90d622eb py3: use print_function in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 28741
diff changeset
    82
    print("* empty file y created")
20045
b3684fd2ff1a scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents: 20041
diff changeset
    83
    # should recreate the object
b3684fd2ff1a scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents: 20041
diff changeset
    84
    repo.cached
b3684fd2ff1a scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents: 20041
diff changeset
    85
b3684fd2ff1a scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents: 20041
diff changeset
    86
    f = open('y', 'w')
b3684fd2ff1a scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents: 20041
diff changeset
    87
    f.write('A')
b3684fd2ff1a scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents: 20041
diff changeset
    88
    f.close()
b3684fd2ff1a scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents: 20041
diff changeset
    89
    repo.invalidate()
28742
a08c90d622eb py3: use print_function in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 28741
diff changeset
    90
    print("* file y changed size")
20045
b3684fd2ff1a scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents: 20041
diff changeset
    91
    # should recreate the object
b3684fd2ff1a scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents: 20041
diff changeset
    92
    repo.cached
b3684fd2ff1a scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents: 20041
diff changeset
    93
b3684fd2ff1a scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents: 20041
diff changeset
    94
    f = scmutil.opener('.')('y', 'w', atomictemp=True)
b3684fd2ff1a scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents: 20041
diff changeset
    95
    f.write('B')
b3684fd2ff1a scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents: 20041
diff changeset
    96
    f.close()
b3684fd2ff1a scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents: 20041
diff changeset
    97
b3684fd2ff1a scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents: 20041
diff changeset
    98
    repo.invalidate()
28742
a08c90d622eb py3: use print_function in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 28741
diff changeset
    99
    print("* file y changed inode")
20045
b3684fd2ff1a scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents: 20041
diff changeset
   100
    repo.cached
b3684fd2ff1a scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents: 20041
diff changeset
   101
b3684fd2ff1a scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents: 20041
diff changeset
   102
    f = scmutil.opener('.')('x', 'w', atomictemp=True)
b3684fd2ff1a scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents: 20041
diff changeset
   103
    f.write('c')
b3684fd2ff1a scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents: 20041
diff changeset
   104
    f.close()
b3684fd2ff1a scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents: 20041
diff changeset
   105
    f = scmutil.opener('.')('y', 'w', atomictemp=True)
b3684fd2ff1a scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents: 20041
diff changeset
   106
    f.write('C')
b3684fd2ff1a scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents: 20041
diff changeset
   107
    f.close()
b3684fd2ff1a scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents: 20041
diff changeset
   108
b3684fd2ff1a scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents: 20041
diff changeset
   109
    repo.invalidate()
28742
a08c90d622eb py3: use print_function in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 28741
diff changeset
   110
    print("* both files changed inode")
20045
b3684fd2ff1a scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents: 20041
diff changeset
   111
    repo.cached
b3684fd2ff1a scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents: 20041
diff changeset
   112
14928
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
   113
def fakeuncacheable():
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
   114
    def wrapcacheable(orig, *args, **kwargs):
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
   115
        return False
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
   116
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
   117
    def wrapinit(orig, *args, **kwargs):
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
   118
        pass
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
   119
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
   120
    originit = extensions.wrapfunction(util.cachestat, '__init__', wrapinit)
14937
0b3e57c1b8c0 filecache: fix check-code complaint
Matt Mackall <mpm@selenic.com>
parents: 14928
diff changeset
   121
    origcacheable = extensions.wrapfunction(util.cachestat, 'cacheable',
0b3e57c1b8c0 filecache: fix check-code complaint
Matt Mackall <mpm@selenic.com>
parents: 14928
diff changeset
   122
                                            wrapcacheable)
14928
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
   123
20045
b3684fd2ff1a scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents: 20041
diff changeset
   124
    for fn in ['x', 'y']:
b3684fd2ff1a scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents: 20041
diff changeset
   125
        try:
b3684fd2ff1a scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents: 20041
diff changeset
   126
            os.remove(fn)
b3684fd2ff1a scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents: 20041
diff changeset
   127
        except OSError:
b3684fd2ff1a scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents: 20041
diff changeset
   128
            pass
14928
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
   129
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
   130
    basic(fakerepo())
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
   131
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
   132
    util.cachestat.cacheable = origcacheable
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
   133
    util.cachestat.__init__ = originit
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
   134
18313
3e4a944c0d04 destroyed: keep the filecache in sync with __dict__ (issue3335) (issue3693) (issue3743)
Idan Kamara <idankk86@gmail.com>
parents: 16688
diff changeset
   135
def test_filecache_synced():
26098
ce26928cbe41 spelling: behaviour -> behavior
timeless@mozdev.org
parents: 20045
diff changeset
   136
    # test old behavior that caused filecached properties to go out of sync
18313
3e4a944c0d04 destroyed: keep the filecache in sync with __dict__ (issue3335) (issue3693) (issue3743)
Idan Kamara <idankk86@gmail.com>
parents: 16688
diff changeset
   137
    os.system('hg init && echo a >> a && hg ci -qAm.')
3e4a944c0d04 destroyed: keep the filecache in sync with __dict__ (issue3335) (issue3693) (issue3743)
Idan Kamara <idankk86@gmail.com>
parents: 16688
diff changeset
   138
    repo = hg.repository(ui.ui())
3e4a944c0d04 destroyed: keep the filecache in sync with __dict__ (issue3335) (issue3693) (issue3743)
Idan Kamara <idankk86@gmail.com>
parents: 16688
diff changeset
   139
    # first rollback clears the filecache, but changelog to stays in __dict__
3e4a944c0d04 destroyed: keep the filecache in sync with __dict__ (issue3335) (issue3693) (issue3743)
Idan Kamara <idankk86@gmail.com>
parents: 16688
diff changeset
   140
    repo.rollback()
3e4a944c0d04 destroyed: keep the filecache in sync with __dict__ (issue3335) (issue3693) (issue3743)
Idan Kamara <idankk86@gmail.com>
parents: 16688
diff changeset
   141
    repo.commit('.')
3e4a944c0d04 destroyed: keep the filecache in sync with __dict__ (issue3335) (issue3693) (issue3743)
Idan Kamara <idankk86@gmail.com>
parents: 16688
diff changeset
   142
    # second rollback comes along and touches the changelog externally
3e4a944c0d04 destroyed: keep the filecache in sync with __dict__ (issue3335) (issue3693) (issue3743)
Idan Kamara <idankk86@gmail.com>
parents: 16688
diff changeset
   143
    # (file is moved)
3e4a944c0d04 destroyed: keep the filecache in sync with __dict__ (issue3335) (issue3693) (issue3743)
Idan Kamara <idankk86@gmail.com>
parents: 16688
diff changeset
   144
    repo.rollback()
3e4a944c0d04 destroyed: keep the filecache in sync with __dict__ (issue3335) (issue3693) (issue3743)
Idan Kamara <idankk86@gmail.com>
parents: 16688
diff changeset
   145
    # but since changelog isn't under the filecache control anymore, we don't
3e4a944c0d04 destroyed: keep the filecache in sync with __dict__ (issue3335) (issue3693) (issue3743)
Idan Kamara <idankk86@gmail.com>
parents: 16688
diff changeset
   146
    # see that it changed, and return the old changelog without reconstructing
3e4a944c0d04 destroyed: keep the filecache in sync with __dict__ (issue3335) (issue3693) (issue3743)
Idan Kamara <idankk86@gmail.com>
parents: 16688
diff changeset
   147
    # it
3e4a944c0d04 destroyed: keep the filecache in sync with __dict__ (issue3335) (issue3693) (issue3743)
Idan Kamara <idankk86@gmail.com>
parents: 16688
diff changeset
   148
    repo.commit('.')
3e4a944c0d04 destroyed: keep the filecache in sync with __dict__ (issue3335) (issue3693) (issue3743)
Idan Kamara <idankk86@gmail.com>
parents: 16688
diff changeset
   149
18316
f36375576ed5 filecache: create an entry in _filecache when __set__ is called for a missing one
Idan Kamara <idankk86@gmail.com>
parents: 18313
diff changeset
   150
def setbeforeget(repo):
f36375576ed5 filecache: create an entry in _filecache when __set__ is called for a missing one
Idan Kamara <idankk86@gmail.com>
parents: 18313
diff changeset
   151
    os.remove('x')
20045
b3684fd2ff1a scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents: 20041
diff changeset
   152
    os.remove('y')
20040
ed80cecdfc57 test-filecache.py: make setbeforeget test clearer
Siddharth Agarwal <sid0@fb.com>
parents: 18316
diff changeset
   153
    repo.cached = 'string set externally'
18316
f36375576ed5 filecache: create an entry in _filecache when __set__ is called for a missing one
Idan Kamara <idankk86@gmail.com>
parents: 18313
diff changeset
   154
    repo.invalidate()
28742
a08c90d622eb py3: use print_function in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 28741
diff changeset
   155
    print("* neither file exists")
a08c90d622eb py3: use print_function in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 28741
diff changeset
   156
    print(repo.cached)
18316
f36375576ed5 filecache: create an entry in _filecache when __set__ is called for a missing one
Idan Kamara <idankk86@gmail.com>
parents: 18313
diff changeset
   157
    repo.invalidate()
f36375576ed5 filecache: create an entry in _filecache when __set__ is called for a missing one
Idan Kamara <idankk86@gmail.com>
parents: 18313
diff changeset
   158
    f = open('x', 'w')
f36375576ed5 filecache: create an entry in _filecache when __set__ is called for a missing one
Idan Kamara <idankk86@gmail.com>
parents: 18313
diff changeset
   159
    f.write('a')
f36375576ed5 filecache: create an entry in _filecache when __set__ is called for a missing one
Idan Kamara <idankk86@gmail.com>
parents: 18313
diff changeset
   160
    f.close()
28742
a08c90d622eb py3: use print_function in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 28741
diff changeset
   161
    print("* file x created")
a08c90d622eb py3: use print_function in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 28741
diff changeset
   162
    print(repo.cached)
18316
f36375576ed5 filecache: create an entry in _filecache when __set__ is called for a missing one
Idan Kamara <idankk86@gmail.com>
parents: 18313
diff changeset
   163
20045
b3684fd2ff1a scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents: 20041
diff changeset
   164
    repo.cached = 'string 2 set externally'
b3684fd2ff1a scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents: 20041
diff changeset
   165
    repo.invalidate()
28742
a08c90d622eb py3: use print_function in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 28741
diff changeset
   166
    print("* string set externally again")
a08c90d622eb py3: use print_function in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 28741
diff changeset
   167
    print(repo.cached)
20045
b3684fd2ff1a scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents: 20041
diff changeset
   168
b3684fd2ff1a scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents: 20041
diff changeset
   169
    repo.invalidate()
b3684fd2ff1a scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents: 20041
diff changeset
   170
    f = open('y', 'w')
b3684fd2ff1a scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents: 20041
diff changeset
   171
    f.write('b')
b3684fd2ff1a scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents: 20041
diff changeset
   172
    f.close()
28742
a08c90d622eb py3: use print_function in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 28741
diff changeset
   173
    print("* file y created")
a08c90d622eb py3: use print_function in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 28741
diff changeset
   174
    print(repo.cached)
20045
b3684fd2ff1a scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents: 20041
diff changeset
   175
28742
a08c90d622eb py3: use print_function in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 28741
diff changeset
   176
print('basic:')
a08c90d622eb py3: use print_function in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 28741
diff changeset
   177
print()
14928
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
   178
basic(fakerepo())
28742
a08c90d622eb py3: use print_function in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 28741
diff changeset
   179
print()
a08c90d622eb py3: use print_function in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 28741
diff changeset
   180
print('fakeuncacheable:')
a08c90d622eb py3: use print_function in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 28741
diff changeset
   181
print()
14928
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
   182
fakeuncacheable()
18313
3e4a944c0d04 destroyed: keep the filecache in sync with __dict__ (issue3335) (issue3693) (issue3743)
Idan Kamara <idankk86@gmail.com>
parents: 16688
diff changeset
   183
test_filecache_synced()
28742
a08c90d622eb py3: use print_function in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 28741
diff changeset
   184
print()
a08c90d622eb py3: use print_function in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 28741
diff changeset
   185
print('setbeforeget:')
a08c90d622eb py3: use print_function in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 28741
diff changeset
   186
print()
18316
f36375576ed5 filecache: create an entry in _filecache when __set__ is called for a missing one
Idan Kamara <idankk86@gmail.com>
parents: 18313
diff changeset
   187
setbeforeget(fakerepo())