annotate hgext3rd/evolve/obscache.py @ 2306:b33bc2f37e89

obscache: have the obsstore fix empty file cachekey Before this change, the missing file and empty file returned different value.
author Pierre-Yves David <pierre-yves.david@ens-lyon.org>
date Tue, 02 May 2017 16:10:14 +0200
parents a786240c95bd
children 0d2e0e8e76f6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2294
75996eafab43 perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
1 # Code dedicated to an cache around obsolescence property
75996eafab43 perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
2 #
75996eafab43 perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
3 # This module content aims at being upstreamed.
75996eafab43 perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
4 #
75996eafab43 perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
5 # Copyright 2017 Pierre-Yves David <pierre-yves.david@ens-lyon.org>
75996eafab43 perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
6 #
75996eafab43 perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
7 # This software may be used and distributed according to the terms of the
75996eafab43 perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
8 # GNU General Public License version 2 or any later version.
75996eafab43 perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
9
2296
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
10 import hashlib
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
11 import struct
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
12 import weakref
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
13 import errno
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
14
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
15 from mercurial import (
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
16 localrepo,
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
17 obsolete,
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
18 phases,
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
19 node,
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
20 )
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
21
2294
75996eafab43 perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
22 from . import (
75996eafab43 perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
23 exthelper,
75996eafab43 perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
24 )
75996eafab43 perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
25
75996eafab43 perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
26 eh = exthelper.exthelper()
75996eafab43 perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
27
75996eafab43 perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
28 try:
75996eafab43 perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
29 obsstorefilecache = localrepo.localrepository.obsstore
75996eafab43 perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
30 except AttributeError:
75996eafab43 perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
31 # XXX hg-3.8 compat
75996eafab43 perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
32 #
75996eafab43 perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
33 # mercurial 3.8 has issue with accessing file cache property from their
75996eafab43 perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
34 # cache. This is fix by 36fbd72c2f39fef8ad52d7c559906c2bc388760c in core
75996eafab43 perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
35 # and shipped in 3.9
75996eafab43 perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
36 obsstorefilecache = localrepo.localrepository.__dict__['obsstore']
75996eafab43 perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
37
75996eafab43 perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
38 # obsstore is a filecache so we have do to some spacial dancing
75996eafab43 perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
39 @eh.wrapfunction(obsstorefilecache, 'func')
75996eafab43 perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
40 def obsstorewithcache(orig, repo):
75996eafab43 perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
41 obsstore = orig(repo)
2296
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
42 obsstore.obscache = obscache(repo.unfiltered())
2294
75996eafab43 perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
43
75996eafab43 perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
44 class cachekeyobsstore(obsstore.__class__):
75996eafab43 perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
45
75996eafab43 perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
46 _obskeysize = 200
75996eafab43 perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
47
75996eafab43 perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
48 def cachekey(self, index=None):
75996eafab43 perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
49 """return (current-length, cachekey)
75996eafab43 perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
50
75996eafab43 perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
51 'current-length': is the current length of the obsstore storage file,
75996eafab43 perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
52 'cachekey' is the hash of the last 200 bytes ending at 'index'.
75996eafab43 perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
53
75996eafab43 perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
54 if 'index' is unspecified, current obsstore length is used.
75996eafab43 perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
55 Cacheckey will be set to null id if the obstore is empty.
75996eafab43 perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
56
75996eafab43 perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
57 If the index specified is higher than the current obsstore file
75996eafab43 perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
58 length, cachekey will be set to None."""
2306
b33bc2f37e89 obscache: have the obsstore fix empty file cachekey
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2305
diff changeset
59 # default value
b33bc2f37e89 obscache: have the obsstore fix empty file cachekey
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2305
diff changeset
60 obsstoresize = 0
b33bc2f37e89 obscache: have the obsstore fix empty file cachekey
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2305
diff changeset
61 keydata = ''
b33bc2f37e89 obscache: have the obsstore fix empty file cachekey
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2305
diff changeset
62 # try to get actual data from the obsstore
2294
75996eafab43 perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
63 try:
75996eafab43 perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
64 with self.svfs('obsstore') as obsfile:
75996eafab43 perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
65 obsfile.seek(0, 2)
75996eafab43 perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
66 obsstoresize = obsfile.tell()
75996eafab43 perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
67 if index is None:
75996eafab43 perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
68 index = obsstoresize
75996eafab43 perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
69 elif obsstoresize < index:
75996eafab43 perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
70 return obsstoresize, None
75996eafab43 perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
71 actualsize = min(index, self._obskeysize)
2306
b33bc2f37e89 obscache: have the obsstore fix empty file cachekey
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2305
diff changeset
72 if actualsize:
b33bc2f37e89 obscache: have the obsstore fix empty file cachekey
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2305
diff changeset
73 obsfile.seek(index - actualsize, 0)
b33bc2f37e89 obscache: have the obsstore fix empty file cachekey
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2305
diff changeset
74 keydata = obsfile.read(actualsize)
2294
75996eafab43 perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
75 except (OSError, IOError) as e:
75996eafab43 perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
76 if e.errno != errno.ENOENT:
75996eafab43 perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
77 raise
2306
b33bc2f37e89 obscache: have the obsstore fix empty file cachekey
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2305
diff changeset
78 key = hashlib.sha1(keydata).digest()
b33bc2f37e89 obscache: have the obsstore fix empty file cachekey
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2305
diff changeset
79 return obsstoresize, key
2294
75996eafab43 perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
80
75996eafab43 perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
81 obsstore.__class__ = cachekeyobsstore
75996eafab43 perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
82
75996eafab43 perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
83 return obsstore
2295
017b971ba28f perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2294
diff changeset
84
017b971ba28f perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2294
diff changeset
85 def getcachekey(repo):
017b971ba28f perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2294
diff changeset
86 """get a cache key covering the changesets and obsmarkers content
017b971ba28f perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2294
diff changeset
87
017b971ba28f perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2294
diff changeset
88 IT contains the following data. Combined with 'upgradeneeded' it allows to
017b971ba28f perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2294
diff changeset
89 do iterative upgrade for cache depending of theses two data.
017b971ba28f perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2294
diff changeset
90
017b971ba28f perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2294
diff changeset
91 The cache key parts are"
017b971ba28f perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2294
diff changeset
92 - tip-rev,
017b971ba28f perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2294
diff changeset
93 - tip-node,
017b971ba28f perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2294
diff changeset
94 - obsstore-length (nb markers),
017b971ba28f perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2294
diff changeset
95 - obsstore-file-size (in bytes),
017b971ba28f perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2294
diff changeset
96 - obsstore "cache key"
017b971ba28f perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2294
diff changeset
97 """
017b971ba28f perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2294
diff changeset
98 assert repo.filtername is None
017b971ba28f perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2294
diff changeset
99 cl = repo.changelog
017b971ba28f perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2294
diff changeset
100 index, key = repo.obsstore.cachekey()
017b971ba28f perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2294
diff changeset
101 tiprev = len(cl) - 1
017b971ba28f perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2294
diff changeset
102 return (tiprev,
017b971ba28f perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2294
diff changeset
103 cl.node(tiprev),
017b971ba28f perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2294
diff changeset
104 len(repo.obsstore),
017b971ba28f perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2294
diff changeset
105 index,
017b971ba28f perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2294
diff changeset
106 key)
017b971ba28f perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2294
diff changeset
107
017b971ba28f perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2294
diff changeset
108 def upgradeneeded(repo, key):
017b971ba28f perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2294
diff changeset
109 """return (valid, start-rev, start-obs-idx)
017b971ba28f perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2294
diff changeset
110
017b971ba28f perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2294
diff changeset
111 'valid': is "False" if older cache value needs invalidation,
017b971ba28f perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2294
diff changeset
112
017b971ba28f perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2294
diff changeset
113 'start-rev': first revision not in the cache. None if cache is up to date,
017b971ba28f perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2294
diff changeset
114
017b971ba28f perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2294
diff changeset
115 'start-obs-idx': index of the first obs-markers not in the cache. None is
017b971ba28f perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2294
diff changeset
116 up to date.
017b971ba28f perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2294
diff changeset
117 """
017b971ba28f perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2294
diff changeset
118
017b971ba28f perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2294
diff changeset
119 # XXX ideally, this function would return a bounded amount of changeset and
017b971ba28f perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2294
diff changeset
120 # obsmarkers and the associated new cache key. Otherwise we are exposed to
017b971ba28f perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2294
diff changeset
121 # a race condition between the time the cache is updated and the new cache
017b971ba28f perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2294
diff changeset
122 # key is computed. (however, we do not want to compute the full new cache
017b971ba28f perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2294
diff changeset
123 # key in all case because we want to skip reading the obsstore content. We
017b971ba28f perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2294
diff changeset
124 # could have a smarter implementation here.
017b971ba28f perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2294
diff changeset
125 #
2300
01efebff13ec obscache: skip the cache entirely if not up to date
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2298
diff changeset
126 # In pratice the cache is only updated after each transaction within a
2295
017b971ba28f perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2294
diff changeset
127 # lock. So we should be fine. We could enforce this with a new repository
017b971ba28f perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2294
diff changeset
128 # requirement (or fix the race, that is not too hard).
017b971ba28f perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2294
diff changeset
129 invalid = (False, 0, 0)
017b971ba28f perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2294
diff changeset
130 if key is None:
017b971ba28f perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2294
diff changeset
131 return invalid
017b971ba28f perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2294
diff changeset
132
017b971ba28f perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2294
diff changeset
133 ### Is the cache valid ?
017b971ba28f perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2294
diff changeset
134 keytiprev, keytipnode, keyobslength, keyobssize, keyobskey = key
017b971ba28f perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2294
diff changeset
135 # check for changelog strip
017b971ba28f perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2294
diff changeset
136 cl = repo.changelog
017b971ba28f perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2294
diff changeset
137 tiprev = len(cl) - 1
017b971ba28f perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2294
diff changeset
138 if (tiprev < keytiprev
017b971ba28f perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2294
diff changeset
139 or cl.node(keytiprev) != keytipnode):
017b971ba28f perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2294
diff changeset
140 return invalid
017b971ba28f perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2294
diff changeset
141 # check for obsstore strip
017b971ba28f perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2294
diff changeset
142 obssize, obskey = repo.obsstore.cachekey(index=keyobssize)
017b971ba28f perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2294
diff changeset
143 if obskey != keyobskey:
017b971ba28f perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2294
diff changeset
144 return invalid
017b971ba28f perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2294
diff changeset
145
017b971ba28f perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2294
diff changeset
146 ### cache is valid, is there anything to update
017b971ba28f perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2294
diff changeset
147
017b971ba28f perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2294
diff changeset
148 # any new changesets ?
017b971ba28f perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2294
diff changeset
149 startrev = None
017b971ba28f perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2294
diff changeset
150 if keytiprev < tiprev:
017b971ba28f perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2294
diff changeset
151 startrev = keytiprev + 1
017b971ba28f perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2294
diff changeset
152
017b971ba28f perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2294
diff changeset
153 # any new markers
017b971ba28f perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2294
diff changeset
154 startidx = None
017b971ba28f perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2294
diff changeset
155 if keyobssize < obssize:
017b971ba28f perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2294
diff changeset
156 startidx = keyobslength
017b971ba28f perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2294
diff changeset
157
017b971ba28f perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2294
diff changeset
158 return True, startrev, startidx
2296
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
159
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
160 class obscache(object):
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
161 """cache the "does a rev" is the precursors of some obsmarkers data
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
162
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
163 This is not directly holding the "is this revision obsolete" information,
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
164 because phases data gets into play here. However, it allow to compute the
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
165 "obsolescence" set without reading the obsstore content.
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
166
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
167 Implementation note #1:
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
168
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
169 The obsstore is implementing only half of the transaction logic it
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
170 should. It properly record the starting point of the obsstore to allow
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
171 clean rollback. However it still write to the obsstore file directly
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
172 during the transaction. Instead it should be keeping data in memory and
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
173 write to a '.pending' file to make the data vailable for hooks.
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
174
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
175 This cache is not going futher than what the obstore is doing, so it does
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
176 not has any '.pending' logic. When the obsstore gains proper '.pending'
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
177 support, adding it to this cache should not be too hard. As the flag
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
178 always move from 0 to 1, we could have a second '.pending' cache file to
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
179 be read. If flag is set in any of them, the value is 1. For the same
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
180 reason, updating the file in place should be possible.
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
181
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
182 Implementation note #2:
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
183
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
184 Instead of having a large final update run, we could update this cache at
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
185 the level adding a new changeset or a new obsmarkers. More on this in the
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
186 'update code'.
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
187
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
188 Implementation note #3:
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
189
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
190 Storage-wise, we could have a "start rev" to avoid storing useless
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
191 zero. That would be especially useful for the '.pending' overlay.
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
192 """
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
193
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
194 _filepath = 'cache/evoext-obscache-00'
2302
acd2431dff29 obscache: update the format to allow negative tiprev
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2301
diff changeset
195 _headerformat = '>q20sQQ20s'
2296
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
196
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
197 def __init__(self, repo):
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
198 self._vfs = repo.vfs
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
199 # The cache key parts are"
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
200 # - tip-rev,
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
201 # - tip-node,
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
202 # - obsstore-length (nb markers),
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
203 # - obsstore-file-size (in bytes),
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
204 # - obsstore "cache key"
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
205 self._cachekey = None
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
206 self._data = bytearray()
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
207
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
208 def get(self, rev):
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
209 """return True if "rev" is used as "precursors for any obsmarkers
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
210
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
211 Make sure the cache has been updated to match the repository content before using it"""
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
212 return self._data[rev]
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
213
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
214 def clear(self):
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
215 """invalidate the cache content"""
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
216 self._cachekey = None
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
217 self._data = bytearray()
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
218
2300
01efebff13ec obscache: skip the cache entirely if not up to date
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2298
diff changeset
219 def uptodate(self, repo):
2301
54b2fddbc2f5 obscache: load the disk data before checking is the cache is up to date
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2300
diff changeset
220 if self._cachekey is None:
54b2fddbc2f5 obscache: load the disk data before checking is the cache is up to date
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2300
diff changeset
221 self.load(repo)
2300
01efebff13ec obscache: skip the cache entirely if not up to date
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2298
diff changeset
222 valid, startrev, startidx = upgradeneeded(repo, self._cachekey)
01efebff13ec obscache: skip the cache entirely if not up to date
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2298
diff changeset
223 return (valid and startrev is None and startidx is None)
01efebff13ec obscache: skip the cache entirely if not up to date
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2298
diff changeset
224
2296
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
225 def update(self, repo):
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
226 """Iteratively update the cache with new repository data"""
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
227 # If we do not have any data, try loading from disk
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
228 if self._cachekey is None:
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
229 self.load(repo)
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
230
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
231 valid, startrev, startidx = upgradeneeded(repo, self._cachekey)
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
232 if not valid:
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
233 self.clear()
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
234
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
235 if startrev is None and startidx is None:
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
236 return
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
237
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
238 # process the new changesets
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
239 cl = repo.changelog
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
240 if startrev is not None:
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
241 node = cl.node
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
242 # Note:
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
243 #
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
244 # Newly added changeset might be affected by obsolescence markers
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
245 # we already have locally. So we needs to have soem global
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
246 # knowledge about the markers to handle that question. Right this
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
247 # requires parsing all markers in the obsstore. However, we could
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
248 # imagine using various optimisation (eg: bloom filter, other on
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
249 # disk cache) to remove this full parsing.
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
250 #
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
251 # For now we stick to the simpler approach or paying the
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
252 # performance cost on new changesets.
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
253 succs = repo.obsstore.successors
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
254 for r in cl.revs(startrev):
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
255 if node(r) in succs:
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
256 val = 1
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
257 else:
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
258 val = 0
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
259 self._data.append(val)
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
260 assert len(self._data) == len(cl), (len(self._data), len(cl))
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
261
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
262 # process the new obsmarkers
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
263 if startidx is not None:
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
264 rev = cl.nodemap.get
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
265 markers = repo.obsstore._all
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
266 # Note:
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
267 #
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
268 # There are no actually needs to load the full obsstore here,
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
269 # since we only read the latest ones. We do it for simplicity in
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
270 # the first implementation. Loading the full obsstore has a
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
271 # performance cost and should go away in this case too. We have
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
272 # two simples options for that:
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
273 #
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
274 # 1) provide and API to start reading markers from a byte offset
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
275 # (we have that data in the cache key)
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
276 #
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
277 # 2) directly update the cache at a lower level, in the code
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
278 # responsible for adding a markers.
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
279 #
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
280 # Option 2 is probably a bit more invasive, but more solid on the long run
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
281
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
282 for i in xrange(startidx, len(repo.obsstore)):
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
283 r = rev(markers[i][0])
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
284 # If markers affect a newly added nodes, it would have been
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
285 # caught in the previous loop, (so we skip < startrev)
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
286 if r is not None and (startrev is None or r < startrev):
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
287 self._data[r] = 1
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
288
2300
01efebff13ec obscache: skip the cache entirely if not up to date
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2298
diff changeset
289 assert repo._currentlock(repo._lockref) is not None
01efebff13ec obscache: skip the cache entirely if not up to date
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2298
diff changeset
290 # XXX note that there are a potential race condition here, since the
01efebff13ec obscache: skip the cache entirely if not up to date
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2298
diff changeset
291 # repo "might" have changed side the cache update above. However, this
01efebff13ec obscache: skip the cache entirely if not up to date
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2298
diff changeset
292 # code will only be running in a lock so we ignore the issue for now.
2296
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
293 #
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
294 # To work around this, 'upgradeneeded' should return a bounded amount
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
295 # of changeset and markers to read with their associated cachekey. see
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
296 # 'upgradeneeded' for detail.
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
297 self._cachekey = getcachekey(repo)
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
298
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
299 def save(self, repo):
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
300 """save the data to disk"""
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
301
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
302 # XXX it happens that the obsstore is (buggilly) always up to date on disk
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
303 if self._cachekey is None:
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
304 return
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
305
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
306 with repo.vfs(self._filepath, 'w', atomictemp=True) as cachefile:
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
307 headerdata = struct.pack(self._headerformat, *self._cachekey)
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
308 cachefile.write(headerdata)
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
309 cachefile.write(self._data)
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
310
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
311 def load(self, repo):
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
312 """load data from disk"""
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
313 assert repo.filtername is None
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
314
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
315 data = repo.vfs.tryread(self._filepath)
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
316 if not data:
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
317 return
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
318
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
319 headersize = struct.calcsize(self._headerformat)
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
320 self._cachekey = struct.unpack(self._headerformat, data[:headersize])
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
321 self._data = bytearray(data[headersize:])
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
322
2300
01efebff13ec obscache: skip the cache entirely if not up to date
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2298
diff changeset
323 def _computeobsoleteset(orig, repo):
2298
8199204274f0 perf: use the cache to compute the obsolete set.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2297
diff changeset
324 """the set of obsolete revisions"""
8199204274f0 perf: use the cache to compute the obsolete set.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2297
diff changeset
325 obs = set()
2300
01efebff13ec obscache: skip the cache entirely if not up to date
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2298
diff changeset
326 repo = repo.unfiltered()
2298
8199204274f0 perf: use the cache to compute the obsolete set.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2297
diff changeset
327 notpublic = repo._phasecache.getrevset(repo, (phases.draft, phases.secret))
8199204274f0 perf: use the cache to compute the obsolete set.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2297
diff changeset
328 if notpublic:
8199204274f0 perf: use the cache to compute the obsolete set.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2297
diff changeset
329 obscache = repo.obsstore.obscache
2300
01efebff13ec obscache: skip the cache entirely if not up to date
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2298
diff changeset
330 # Since we warm the cache at the end of every transaction, the cache
01efebff13ec obscache: skip the cache entirely if not up to date
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2298
diff changeset
331 # should be up to date. However a non-enabled client might have touced
01efebff13ec obscache: skip the cache entirely if not up to date
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2298
diff changeset
332 # the repository.
01efebff13ec obscache: skip the cache entirely if not up to date
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2298
diff changeset
333 #
01efebff13ec obscache: skip the cache entirely if not up to date
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2298
diff changeset
334 # Updating the cache without a lock is sloppy, so we fallback to the
01efebff13ec obscache: skip the cache entirely if not up to date
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2298
diff changeset
335 # old method and rely on the fact the next transaction will write the
01efebff13ec obscache: skip the cache entirely if not up to date
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2298
diff changeset
336 # cache down anyway.
01efebff13ec obscache: skip the cache entirely if not up to date
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2298
diff changeset
337 #
01efebff13ec obscache: skip the cache entirely if not up to date
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2298
diff changeset
338 # With the current implementation updating the cache will requires to
01efebff13ec obscache: skip the cache entirely if not up to date
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2298
diff changeset
339 # load the obsstore anyway. Once loaded, hitting the obsstore directly
01efebff13ec obscache: skip the cache entirely if not up to date
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2298
diff changeset
340 # will be about as fast..
01efebff13ec obscache: skip the cache entirely if not up to date
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2298
diff changeset
341 if not obscache.uptodate(repo):
2304
2f15090712fe obscache: still update and use the cache during transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2303
diff changeset
342 if repo.currenttransaction() is None:
2305
a786240c95bd obscache: log case where the cache is not up to date
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2304
diff changeset
343 repo.ui.log('evoext-obscache',
a786240c95bd obscache: log case where the cache is not up to date
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2304
diff changeset
344 'obscache is out of date, '
a786240c95bd obscache: log case where the cache is not up to date
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2304
diff changeset
345 'falling back to slower obsstore version\n')
a786240c95bd obscache: log case where the cache is not up to date
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2304
diff changeset
346 repo.ui.debug('obscache is out of date')
2304
2f15090712fe obscache: still update and use the cache during transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2303
diff changeset
347 return orig(repo)
2f15090712fe obscache: still update and use the cache during transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2303
diff changeset
348 else:
2f15090712fe obscache: still update and use the cache during transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2303
diff changeset
349 # If a transaction is open, it is worthwhile to update and use the
2f15090712fe obscache: still update and use the cache during transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2303
diff changeset
350 # cache as it will be written on disk when the transaction close.
2f15090712fe obscache: still update and use the cache during transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2303
diff changeset
351 obscache.update(repo)
2298
8199204274f0 perf: use the cache to compute the obsolete set.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2297
diff changeset
352 isobs = obscache.get
8199204274f0 perf: use the cache to compute the obsolete set.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2297
diff changeset
353 for r in notpublic:
8199204274f0 perf: use the cache to compute the obsolete set.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2297
diff changeset
354 if isobs(r):
8199204274f0 perf: use the cache to compute the obsolete set.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2297
diff changeset
355 obs.add(r)
8199204274f0 perf: use the cache to compute the obsolete set.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2297
diff changeset
356 return obs
8199204274f0 perf: use the cache to compute the obsolete set.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2297
diff changeset
357
8199204274f0 perf: use the cache to compute the obsolete set.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2297
diff changeset
358 @eh.uisetup
8199204274f0 perf: use the cache to compute the obsolete set.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2297
diff changeset
359 def cachefuncs(ui):
2300
01efebff13ec obscache: skip the cache entirely if not up to date
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2298
diff changeset
360 orig = obsolete.cachefuncs['obsolete']
01efebff13ec obscache: skip the cache entirely if not up to date
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2298
diff changeset
361 wrapped = lambda repo: _computeobsoleteset(orig, repo)
01efebff13ec obscache: skip the cache entirely if not up to date
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2298
diff changeset
362 obsolete.cachefuncs['obsolete'] = wrapped
2298
8199204274f0 perf: use the cache to compute the obsolete set.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2297
diff changeset
363
2296
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
364 @eh.reposetup
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
365 def setupcache(ui, repo):
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
366
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
367 class obscacherepo(repo.__class__):
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
368
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
369 @localrepo.unfilteredmethod
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
370 def destroyed(self):
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
371 if 'obsstore' in vars(self):
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
372 self.obsstore.obscache.clear()
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
373
2297
32cdcf493567 perf: warm the cache after all transactions
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2296
diff changeset
374 def transaction(self, *args, **kwargs):
32cdcf493567 perf: warm the cache after all transactions
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2296
diff changeset
375 tr = super(obscacherepo, self).transaction(*args, **kwargs)
32cdcf493567 perf: warm the cache after all transactions
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2296
diff changeset
376 reporef = weakref.ref(self)
32cdcf493567 perf: warm the cache after all transactions
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2296
diff changeset
377
32cdcf493567 perf: warm the cache after all transactions
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2296
diff changeset
378 def _warmcache(tr):
32cdcf493567 perf: warm the cache after all transactions
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2296
diff changeset
379 repo = reporef()
32cdcf493567 perf: warm the cache after all transactions
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2296
diff changeset
380 if repo is None:
32cdcf493567 perf: warm the cache after all transactions
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2296
diff changeset
381 return
2303
8534400111fd obscache: warm the cache in all cases
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2302
diff changeset
382 repo = repo.unfiltered()
8534400111fd obscache: warm the cache in all cases
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2302
diff changeset
383 # As pointed in 'obscache.update', we could have the
8534400111fd obscache: warm the cache in all cases
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2302
diff changeset
384 # changelog and the obsstore in charge of updating the
8534400111fd obscache: warm the cache in all cases
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2302
diff changeset
385 # cache when new items goes it. The tranaction logic would
8534400111fd obscache: warm the cache in all cases
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2302
diff changeset
386 # then only be involved for the 'pending' and final saving
8534400111fd obscache: warm the cache in all cases
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2302
diff changeset
387 # logic.
8534400111fd obscache: warm the cache in all cases
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2302
diff changeset
388 self.obsstore.obscache.update(repo)
8534400111fd obscache: warm the cache in all cases
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2302
diff changeset
389 self.obsstore.obscache.save(repo)
2297
32cdcf493567 perf: warm the cache after all transactions
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2296
diff changeset
390
32cdcf493567 perf: warm the cache after all transactions
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2296
diff changeset
391 tr.addpostclose('warmcache-obscache', _warmcache)
32cdcf493567 perf: warm the cache after all transactions
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2296
diff changeset
392 return tr
32cdcf493567 perf: warm the cache after all transactions
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2296
diff changeset
393
2296
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
394 repo.__class__ = obscacherepo