Mercurial > evolve
annotate hgext3rd/evolve/obscache.py @ 2387:a41d900d015c
dualsourcecache: simplify cachekey.clear
We do not needs the super call anymore and we can make the reset case more
explicit. So we do.
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Wed, 17 May 2017 12:23:10 +0200 |
parents | fab59e2cb05f |
children | 4afbcdcfa9b2 |
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 ( |
2328
7ccacaa38782
obscache: Only access the new obsmarkers for marker update
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2327
diff
changeset
|
16 error, |
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
|
17 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
|
18 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
|
19 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
|
20 node, |
2315
e16f6bef5848
compat: make obscache code compatible with Mercurial version prior to 4.2
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2309
diff
changeset
|
21 util, |
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
|
22 ) |
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
|
23 |
2328
7ccacaa38782
obscache: Only access the new obsmarkers for marker update
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2327
diff
changeset
|
24 from mercurial.i18n import _ |
7ccacaa38782
obscache: Only access the new obsmarkers for marker update
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2327
diff
changeset
|
25 |
2294
75996eafab43
perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
26 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
|
27 exthelper, |
75996eafab43
perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
28 ) |
75996eafab43
perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
29 |
75996eafab43
perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
30 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
|
31 |
75996eafab43
perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
32 try: |
75996eafab43
perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
33 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
|
34 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
|
35 # 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
|
36 # |
75996eafab43
perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
37 # 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
|
38 # 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
|
39 # 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
|
40 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
|
41 |
75996eafab43
perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
42 # 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
|
43 @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
|
44 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
|
45 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
|
46 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
|
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 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
|
49 |
75996eafab43
perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
50 _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
|
51 |
75996eafab43
perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
52 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
|
53 """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
|
54 |
75996eafab43
perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
55 '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
|
56 '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
|
57 |
75996eafab43
perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
58 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
|
59 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
|
60 |
75996eafab43
perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
61 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
|
62 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
|
63 # default value |
b33bc2f37e89
obscache: have the obsstore fix empty file cachekey
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2305
diff
changeset
|
64 obsstoresize = 0 |
b33bc2f37e89
obscache: have the obsstore fix empty file cachekey
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2305
diff
changeset
|
65 keydata = '' |
b33bc2f37e89
obscache: have the obsstore fix empty file cachekey
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2305
diff
changeset
|
66 # 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
|
67 try: |
75996eafab43
perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
68 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
|
69 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
|
70 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
|
71 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
|
72 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
|
73 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
|
74 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
|
75 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
|
76 if actualsize: |
b33bc2f37e89
obscache: have the obsstore fix empty file cachekey
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2305
diff
changeset
|
77 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
|
78 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
|
79 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
|
80 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
|
81 raise |
2354
fed22455e510
obscache: use 'nullid' as the hash of an empty obsstore
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2353
diff
changeset
|
82 if keydata: |
fed22455e510
obscache: use 'nullid' as the hash of an empty obsstore
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2353
diff
changeset
|
83 key = hashlib.sha1(keydata).digest() |
fed22455e510
obscache: use 'nullid' as the hash of an empty obsstore
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2353
diff
changeset
|
84 else: |
fed22455e510
obscache: use 'nullid' as the hash of an empty obsstore
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2353
diff
changeset
|
85 # reusing an existing "empty" value make it easier to define a |
fed22455e510
obscache: use 'nullid' as the hash of an empty obsstore
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2353
diff
changeset
|
86 # default cachekey for 'no data'. |
fed22455e510
obscache: use 'nullid' as the hash of an empty obsstore
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2353
diff
changeset
|
87 key = node.nullid |
2306
b33bc2f37e89
obscache: have the obsstore fix empty file cachekey
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2305
diff
changeset
|
88 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
|
89 |
75996eafab43
perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
90 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
|
91 |
75996eafab43
perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
92 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
|
93 |
2328
7ccacaa38782
obscache: Only access the new obsmarkers for marker update
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2327
diff
changeset
|
94 # XXX copied as is from Mercurial 4.2 and added the "offset" parameters |
7ccacaa38782
obscache: Only access the new obsmarkers for marker update
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2327
diff
changeset
|
95 @util.nogc |
7ccacaa38782
obscache: Only access the new obsmarkers for marker update
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2327
diff
changeset
|
96 def _readmarkers(data, offset=None): |
7ccacaa38782
obscache: Only access the new obsmarkers for marker update
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2327
diff
changeset
|
97 """Read and enumerate markers from raw data""" |
7ccacaa38782
obscache: Only access the new obsmarkers for marker update
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2327
diff
changeset
|
98 off = 0 |
7ccacaa38782
obscache: Only access the new obsmarkers for marker update
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2327
diff
changeset
|
99 diskversion = struct.unpack('>B', data[off:off + 1])[0] |
7ccacaa38782
obscache: Only access the new obsmarkers for marker update
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2327
diff
changeset
|
100 if offset is None: |
7ccacaa38782
obscache: Only access the new obsmarkers for marker update
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2327
diff
changeset
|
101 off += 1 |
7ccacaa38782
obscache: Only access the new obsmarkers for marker update
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2327
diff
changeset
|
102 else: |
7ccacaa38782
obscache: Only access the new obsmarkers for marker update
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2327
diff
changeset
|
103 assert 1 <= offset |
7ccacaa38782
obscache: Only access the new obsmarkers for marker update
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2327
diff
changeset
|
104 off = offset |
7ccacaa38782
obscache: Only access the new obsmarkers for marker update
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2327
diff
changeset
|
105 if diskversion not in obsolete.formats: |
7ccacaa38782
obscache: Only access the new obsmarkers for marker update
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2327
diff
changeset
|
106 raise error.Abort(_('parsing obsolete marker: unknown version %r') |
7ccacaa38782
obscache: Only access the new obsmarkers for marker update
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2327
diff
changeset
|
107 % diskversion) |
7ccacaa38782
obscache: Only access the new obsmarkers for marker update
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2327
diff
changeset
|
108 return diskversion, obsolete.formats[diskversion][0](data, off) |
2295
017b971ba28f
perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2294
diff
changeset
|
109 |
2328
7ccacaa38782
obscache: Only access the new obsmarkers for marker update
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2327
diff
changeset
|
110 def markersfrom(obsstore, byteoffset, firstmarker): |
2345
406c1a57b4ee
obscache: return the new data along-side the upgrade needs (and cache key)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2344
diff
changeset
|
111 if not firstmarker: |
406c1a57b4ee
obscache: return the new data along-side the upgrade needs (and cache key)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2344
diff
changeset
|
112 return list(obsstore) |
406c1a57b4ee
obscache: return the new data along-side the upgrade needs (and cache key)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2344
diff
changeset
|
113 elif '_all' in vars(obsstore): |
2328
7ccacaa38782
obscache: Only access the new obsmarkers for marker update
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2327
diff
changeset
|
114 # if the data are in memory, just use that |
7ccacaa38782
obscache: Only access the new obsmarkers for marker update
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2327
diff
changeset
|
115 return obsstore._all[firstmarker:] |
7ccacaa38782
obscache: Only access the new obsmarkers for marker update
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2327
diff
changeset
|
116 else: |
7ccacaa38782
obscache: Only access the new obsmarkers for marker update
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2327
diff
changeset
|
117 obsdata = obsstore.svfs.tryread('obsstore') |
7ccacaa38782
obscache: Only access the new obsmarkers for marker update
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2327
diff
changeset
|
118 return _readmarkers(obsdata, byteoffset)[1] |
2295
017b971ba28f
perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2294
diff
changeset
|
119 |
017b971ba28f
perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2294
diff
changeset
|
120 |
2357
f787f5406a98
obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2356
diff
changeset
|
121 class dualsourcecache(object): |
f787f5406a98
obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2356
diff
changeset
|
122 """An abstract class for cache that needs both changelog and 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
|
123 |
2357
f787f5406a98
obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2356
diff
changeset
|
124 This class handle the tracking of changelog and obsstore update. It provide |
f787f5406a98
obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2356
diff
changeset
|
125 data to performs incremental update (see the 'updatefrom' function for |
f787f5406a98
obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2356
diff
changeset
|
126 details). This class can also detect stripping of the changelog or the |
f787f5406a98
obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2356
diff
changeset
|
127 obsstore and can reset the cache in this cache (see the 'clear' function |
f787f5406a98
obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2356
diff
changeset
|
128 for details). |
2295
017b971ba28f
perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2294
diff
changeset
|
129 """ |
017b971ba28f
perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2294
diff
changeset
|
130 |
2357
f787f5406a98
obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2356
diff
changeset
|
131 # default key used for an empty cache |
f787f5406a98
obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2356
diff
changeset
|
132 # |
f787f5406a98
obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2356
diff
changeset
|
133 # The cache key covering the changesets and obsmarkers content |
2295
017b971ba28f
perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2294
diff
changeset
|
134 # |
2357
f787f5406a98
obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2356
diff
changeset
|
135 # The cache key parts are: |
f787f5406a98
obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2356
diff
changeset
|
136 # - tip-rev, |
f787f5406a98
obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2356
diff
changeset
|
137 # - tip-node, |
f787f5406a98
obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2356
diff
changeset
|
138 # - obsstore-length (nb markers), |
f787f5406a98
obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2356
diff
changeset
|
139 # - obsstore-file-size (in bytes), |
f787f5406a98
obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2356
diff
changeset
|
140 # - obsstore "cache key" |
2353
393cbaf0d294
obcache: move empty on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2352
diff
changeset
|
141 emptykey = (node.nullrev, node.nullid, 0, 0, node.nullid) |
2376
12386f7f5056
dualsourcecache: add a cache name
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2375
diff
changeset
|
142 _cachename = None # used for error message |
2353
393cbaf0d294
obcache: move empty on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2352
diff
changeset
|
143 |
2357
f787f5406a98
obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2356
diff
changeset
|
144 def __init__(self): |
2359
ff635fa59a25
obscache: makes dualsourcecache compatible with obshashrange cache needs
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2357
diff
changeset
|
145 super(dualsourcecache, self).__init__() |
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
|
146 self._cachekey = None |
2357
f787f5406a98
obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2356
diff
changeset
|
147 |
f787f5406a98
obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2356
diff
changeset
|
148 def _updatefrom(self, repo, revs, obsmarkers): |
f787f5406a98
obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2356
diff
changeset
|
149 """override this method to update your cache data incrementally |
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
|
150 |
2357
f787f5406a98
obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2356
diff
changeset
|
151 revs: list of new revision in the changelog |
f787f5406a98
obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2356
diff
changeset
|
152 obsmarker: list of new obsmarkers in the obsstore |
f787f5406a98
obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2356
diff
changeset
|
153 """ |
f787f5406a98
obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2356
diff
changeset
|
154 raise NotImplementedError |
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
|
155 |
2333
adf114c767ab
obscache: distinct 'clear' and 'reset'
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2330
diff
changeset
|
156 def clear(self, reset=False): |
2357
f787f5406a98
obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2356
diff
changeset
|
157 """invalidate the cache content |
f787f5406a98
obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2356
diff
changeset
|
158 |
f787f5406a98
obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2356
diff
changeset
|
159 if 'reset' is passed, we detected a strip and the cache will have to be |
f787f5406a98
obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2356
diff
changeset
|
160 recomputed. |
f787f5406a98
obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2356
diff
changeset
|
161 """ |
f787f5406a98
obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2356
diff
changeset
|
162 # /!\ IMPORTANT /!\ |
f787f5406a98
obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2356
diff
changeset
|
163 # You must overide this method to actually |
2387
a41d900d015c
dualsourcecache: simplify cachekey.clear
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2385
diff
changeset
|
164 if reset: |
a41d900d015c
dualsourcecache: simplify cachekey.clear
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2385
diff
changeset
|
165 self._cachekey = self.emptykey if reset else None |
a41d900d015c
dualsourcecache: simplify cachekey.clear
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2385
diff
changeset
|
166 else: |
a41d900d015c
dualsourcecache: simplify cachekey.clear
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2385
diff
changeset
|
167 self._cachekey = None |
2359
ff635fa59a25
obscache: makes dualsourcecache compatible with obshashrange cache needs
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2357
diff
changeset
|
168 |
ff635fa59a25
obscache: makes dualsourcecache compatible with obshashrange cache needs
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2357
diff
changeset
|
169 def load(self, repo): |
ff635fa59a25
obscache: makes dualsourcecache compatible with obshashrange cache needs
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2357
diff
changeset
|
170 """Load data from disk |
ff635fa59a25
obscache: makes dualsourcecache compatible with obshashrange cache needs
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2357
diff
changeset
|
171 |
ff635fa59a25
obscache: makes dualsourcecache compatible with obshashrange cache needs
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2357
diff
changeset
|
172 Do not forget to restore the "cachekey" attribute while doing so. |
ff635fa59a25
obscache: makes dualsourcecache compatible with obshashrange cache needs
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2357
diff
changeset
|
173 """ |
ff635fa59a25
obscache: makes dualsourcecache compatible with obshashrange cache needs
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2357
diff
changeset
|
174 raise NotImplementedError |
2357
f787f5406a98
obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2356
diff
changeset
|
175 |
f787f5406a98
obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2356
diff
changeset
|
176 # Useful public function (no need to override them) |
f787f5406a98
obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2356
diff
changeset
|
177 |
f787f5406a98
obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2356
diff
changeset
|
178 def uptodate(self, repo): |
f787f5406a98
obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2356
diff
changeset
|
179 """return True if the cache content is up to date False otherwise |
f787f5406a98
obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2356
diff
changeset
|
180 |
f787f5406a98
obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2356
diff
changeset
|
181 This method can be used to detect of the cache is lagging behind new |
f787f5406a98
obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2356
diff
changeset
|
182 data in either changelog or obsstore. |
f787f5406a98
obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2356
diff
changeset
|
183 """ |
f787f5406a98
obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2356
diff
changeset
|
184 if self._cachekey is None: |
f787f5406a98
obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2356
diff
changeset
|
185 self.load(repo) |
f787f5406a98
obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2356
diff
changeset
|
186 status = self._checkkey(repo.changelog, repo.obsstore) |
f787f5406a98
obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2356
diff
changeset
|
187 return (status is not None |
f787f5406a98
obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2356
diff
changeset
|
188 and status[0] == self._cachekey[0] # tiprev |
f787f5406a98
obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2356
diff
changeset
|
189 and status[1] == self._cachekey[3]) # obssize |
f787f5406a98
obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2356
diff
changeset
|
190 |
f787f5406a98
obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2356
diff
changeset
|
191 def update(self, repo): |
f787f5406a98
obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2356
diff
changeset
|
192 """update the cache with new repository data |
f787f5406a98
obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2356
diff
changeset
|
193 |
f787f5406a98
obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2356
diff
changeset
|
194 The update will be incremental when possible""" |
2359
ff635fa59a25
obscache: makes dualsourcecache compatible with obshashrange cache needs
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2357
diff
changeset
|
195 repo = repo.unfiltered() |
2357
f787f5406a98
obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2356
diff
changeset
|
196 # If we do not have any data, try loading from disk |
f787f5406a98
obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2356
diff
changeset
|
197 if self._cachekey is None: |
f787f5406a98
obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2356
diff
changeset
|
198 self.load(repo) |
f787f5406a98
obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2356
diff
changeset
|
199 |
f787f5406a98
obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2356
diff
changeset
|
200 assert repo.filtername is None |
f787f5406a98
obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2356
diff
changeset
|
201 cl = repo.changelog |
f787f5406a98
obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2356
diff
changeset
|
202 |
f787f5406a98
obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2356
diff
changeset
|
203 upgrade = self._upgradeneeded(repo) |
f787f5406a98
obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2356
diff
changeset
|
204 if upgrade is None: |
f787f5406a98
obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2356
diff
changeset
|
205 return |
f787f5406a98
obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2356
diff
changeset
|
206 |
f787f5406a98
obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2356
diff
changeset
|
207 reset, revs, obsmarkers, obskeypair = upgrade |
f787f5406a98
obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2356
diff
changeset
|
208 if reset or self._cachekey is None: |
2382
42092b9d6d25
dualsourcecache: log cache reset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2380
diff
changeset
|
209 repo.ui.log('evoext-cache', 'strip detected, %s cache reset\n' % self._cachename) |
2357
f787f5406a98
obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2356
diff
changeset
|
210 self.clear(reset=True) |
f787f5406a98
obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2356
diff
changeset
|
211 |
2380
694494619795
cache: track time spend updating various cache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2379
diff
changeset
|
212 starttime = util.timer() |
2357
f787f5406a98
obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2356
diff
changeset
|
213 self._updatefrom(repo, revs, obsmarkers) |
2380
694494619795
cache: track time spend updating various cache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2379
diff
changeset
|
214 duration = util.timer() - starttime |
694494619795
cache: track time spend updating various cache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2379
diff
changeset
|
215 repo.ui.log('evoext-cache', 'updated %s in %.4f seconds (%sr, %so)\n', |
694494619795
cache: track time spend updating various cache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2379
diff
changeset
|
216 self._cachename, duration, len(revs), len(obsmarkers)) |
2295
017b971ba28f
perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2294
diff
changeset
|
217 |
2357
f787f5406a98
obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2356
diff
changeset
|
218 # update the key from the new data |
f787f5406a98
obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2356
diff
changeset
|
219 key = list(self._cachekey) |
f787f5406a98
obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2356
diff
changeset
|
220 if revs: |
f787f5406a98
obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2356
diff
changeset
|
221 key[0] = len(cl) - 1 |
f787f5406a98
obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2356
diff
changeset
|
222 key[1] = cl.node(key[0]) |
f787f5406a98
obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2356
diff
changeset
|
223 if obsmarkers: |
f787f5406a98
obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2356
diff
changeset
|
224 key[2] += len(obsmarkers) |
f787f5406a98
obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2356
diff
changeset
|
225 key[3], key[4] = obskeypair |
f787f5406a98
obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2356
diff
changeset
|
226 self._cachekey = tuple(key) |
f787f5406a98
obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2356
diff
changeset
|
227 |
f787f5406a98
obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2356
diff
changeset
|
228 # from here, there are internal function only |
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
|
229 |
2352
dd8471e54708
obcache: move _checkkey on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2351
diff
changeset
|
230 def _checkkey(self, changelog, obsstore): |
dd8471e54708
obcache: move _checkkey on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2351
diff
changeset
|
231 """internal function""" |
dd8471e54708
obcache: move _checkkey on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2351
diff
changeset
|
232 key = self._cachekey |
dd8471e54708
obcache: move _checkkey on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2351
diff
changeset
|
233 if key is None: |
dd8471e54708
obcache: move _checkkey on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2351
diff
changeset
|
234 return None |
dd8471e54708
obcache: move _checkkey on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2351
diff
changeset
|
235 |
dd8471e54708
obcache: move _checkkey on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2351
diff
changeset
|
236 ### Is the cache valid ? |
dd8471e54708
obcache: move _checkkey on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2351
diff
changeset
|
237 keytiprev, keytipnode, keyobslength, keyobssize, keyobskey = key |
dd8471e54708
obcache: move _checkkey on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2351
diff
changeset
|
238 # check for changelog strip |
dd8471e54708
obcache: move _checkkey on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2351
diff
changeset
|
239 tiprev = len(changelog) - 1 |
dd8471e54708
obcache: move _checkkey on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2351
diff
changeset
|
240 if (tiprev < keytiprev |
dd8471e54708
obcache: move _checkkey on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2351
diff
changeset
|
241 or changelog.node(keytiprev) != keytipnode): |
dd8471e54708
obcache: move _checkkey on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2351
diff
changeset
|
242 return None |
dd8471e54708
obcache: move _checkkey on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2351
diff
changeset
|
243 # check for obsstore strip |
dd8471e54708
obcache: move _checkkey on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2351
diff
changeset
|
244 obssize, obskey = obsstore.cachekey(index=keyobssize) |
dd8471e54708
obcache: move _checkkey on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2351
diff
changeset
|
245 if obskey != keyobskey: |
dd8471e54708
obcache: move _checkkey on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2351
diff
changeset
|
246 return None |
2385
fab59e2cb05f
dualsourcecache: fix obskey return by _checkkey
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2382
diff
changeset
|
247 if obssize != keyobssize: |
fab59e2cb05f
dualsourcecache: fix obskey return by _checkkey
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2382
diff
changeset
|
248 # we want to return the obskey for the new size |
fab59e2cb05f
dualsourcecache: fix obskey return by _checkkey
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2382
diff
changeset
|
249 __, obskey = obsstore.cachekey(index=obssize) |
2352
dd8471e54708
obcache: move _checkkey on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2351
diff
changeset
|
250 return tiprev, obssize, obskey |
dd8471e54708
obcache: move _checkkey on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2351
diff
changeset
|
251 |
2357
f787f5406a98
obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2356
diff
changeset
|
252 def _upgradeneeded(self, repo): |
2351
1bec5ee99674
obcache: move updateneeded on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2347
diff
changeset
|
253 """return (valid, start-rev, start-obs-idx) |
1bec5ee99674
obcache: move updateneeded on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2347
diff
changeset
|
254 |
1bec5ee99674
obcache: move updateneeded on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2347
diff
changeset
|
255 'valid': is "False" if older cache value needs invalidation, |
1bec5ee99674
obcache: move updateneeded on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2347
diff
changeset
|
256 |
1bec5ee99674
obcache: move updateneeded on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2347
diff
changeset
|
257 'start-rev': first revision not in the cache. None if cache is up to date, |
1bec5ee99674
obcache: move updateneeded on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2347
diff
changeset
|
258 |
1bec5ee99674
obcache: move updateneeded on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2347
diff
changeset
|
259 'start-obs-idx': index of the first obs-markers not in the cache. None is |
1bec5ee99674
obcache: move updateneeded on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2347
diff
changeset
|
260 up to date. |
1bec5ee99674
obcache: move updateneeded on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2347
diff
changeset
|
261 """ |
2295
017b971ba28f
perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2294
diff
changeset
|
262 |
2351
1bec5ee99674
obcache: move updateneeded on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2347
diff
changeset
|
263 # We need to ensure we use the same changelog and obsstore through the |
1bec5ee99674
obcache: move updateneeded on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2347
diff
changeset
|
264 # processing. Otherwise some invalidation could update the object and their |
1bec5ee99674
obcache: move updateneeded on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2347
diff
changeset
|
265 # content after we computed the cache key. |
1bec5ee99674
obcache: move updateneeded on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2347
diff
changeset
|
266 cl = repo.changelog |
1bec5ee99674
obcache: move updateneeded on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2347
diff
changeset
|
267 obsstore = repo.obsstore |
1bec5ee99674
obcache: move updateneeded on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2347
diff
changeset
|
268 key = self._cachekey |
1bec5ee99674
obcache: move updateneeded on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2347
diff
changeset
|
269 |
1bec5ee99674
obcache: move updateneeded on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2347
diff
changeset
|
270 reset = False |
2295
017b971ba28f
perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2294
diff
changeset
|
271 |
2352
dd8471e54708
obcache: move _checkkey on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2351
diff
changeset
|
272 status = self._checkkey(cl, obsstore) |
2351
1bec5ee99674
obcache: move updateneeded on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2347
diff
changeset
|
273 if status is None: |
1bec5ee99674
obcache: move updateneeded on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2347
diff
changeset
|
274 reset = True |
2353
393cbaf0d294
obcache: move empty on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2352
diff
changeset
|
275 key = self.emptykey |
2351
1bec5ee99674
obcache: move updateneeded on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2347
diff
changeset
|
276 obssize, obskey = obsstore.cachekey() |
1bec5ee99674
obcache: move updateneeded on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2347
diff
changeset
|
277 tiprev = len(cl) - 1 |
1bec5ee99674
obcache: move updateneeded on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2347
diff
changeset
|
278 else: |
1bec5ee99674
obcache: move updateneeded on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2347
diff
changeset
|
279 tiprev, obssize, obskey = status |
1bec5ee99674
obcache: move updateneeded on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2347
diff
changeset
|
280 |
1bec5ee99674
obcache: move updateneeded on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2347
diff
changeset
|
281 keytiprev, keytipnode, keyobslength, keyobssize, keyobskey = key |
1bec5ee99674
obcache: move updateneeded on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2347
diff
changeset
|
282 |
1bec5ee99674
obcache: move updateneeded on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2347
diff
changeset
|
283 if not reset and keytiprev == tiprev and keyobssize == obssize: |
1bec5ee99674
obcache: move updateneeded on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2347
diff
changeset
|
284 return None # nothing to upgrade |
2295
017b971ba28f
perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2294
diff
changeset
|
285 |
2351
1bec5ee99674
obcache: move updateneeded on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2347
diff
changeset
|
286 ### cache is valid, is there anything to update |
1bec5ee99674
obcache: move updateneeded on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2347
diff
changeset
|
287 |
1bec5ee99674
obcache: move updateneeded on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2347
diff
changeset
|
288 # any new changesets ? |
1bec5ee99674
obcache: move updateneeded on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2347
diff
changeset
|
289 revs = () |
1bec5ee99674
obcache: move updateneeded on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2347
diff
changeset
|
290 if keytiprev < tiprev: |
1bec5ee99674
obcache: move updateneeded on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2347
diff
changeset
|
291 revs = list(cl.revs(start=keytiprev + 1, stop=tiprev)) |
2295
017b971ba28f
perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2294
diff
changeset
|
292 |
2351
1bec5ee99674
obcache: move updateneeded on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2347
diff
changeset
|
293 # any new markers |
1bec5ee99674
obcache: move updateneeded on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2347
diff
changeset
|
294 markers = () |
1bec5ee99674
obcache: move updateneeded on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2347
diff
changeset
|
295 if keyobssize < obssize: |
1bec5ee99674
obcache: move updateneeded on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2347
diff
changeset
|
296 # XXX Three are a small race change here. Since the obsstore might have |
1bec5ee99674
obcache: move updateneeded on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2347
diff
changeset
|
297 # move forward between the time we computed the cache key and we access |
1bec5ee99674
obcache: move updateneeded on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2347
diff
changeset
|
298 # the data. To fix this we need so "up to" argument when fetching the |
1bec5ee99674
obcache: move updateneeded on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2347
diff
changeset
|
299 # markers here. Otherwise we might return more markers than covered by |
1bec5ee99674
obcache: move updateneeded on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2347
diff
changeset
|
300 # the cache key. |
1bec5ee99674
obcache: move updateneeded on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2347
diff
changeset
|
301 # |
1bec5ee99674
obcache: move updateneeded on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2347
diff
changeset
|
302 # In pratice the cache is only updated after each transaction within a |
1bec5ee99674
obcache: move updateneeded on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2347
diff
changeset
|
303 # lock. So we should be fine. We could enforce this with a new repository |
1bec5ee99674
obcache: move updateneeded on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2347
diff
changeset
|
304 # requirement (or fix the race, that is not too hard). |
1bec5ee99674
obcache: move updateneeded on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2347
diff
changeset
|
305 markers = markersfrom(obsstore, keyobssize, keyobslength) |
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
|
306 |
2351
1bec5ee99674
obcache: move updateneeded on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2347
diff
changeset
|
307 return reset, revs, markers, (obssize, obskey) |
1bec5ee99674
obcache: move updateneeded on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2347
diff
changeset
|
308 |
2357
f787f5406a98
obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2356
diff
changeset
|
309 |
f787f5406a98
obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2356
diff
changeset
|
310 class obscache(dualsourcecache): |
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
|
311 """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
|
312 |
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 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
|
314 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
|
315 "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
|
316 |
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 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
|
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 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
|
320 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
|
321 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
|
322 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
|
323 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
|
324 |
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
|
325 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
|
326 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
|
327 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
|
328 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
|
329 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
|
330 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
|
331 |
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
|
332 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
|
333 |
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
|
334 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
|
335 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
|
336 '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
|
337 |
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
|
338 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
|
339 |
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
|
340 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
|
341 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
|
342 """ |
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
|
343 |
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
|
344 _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
|
345 _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
|
346 |
2376
12386f7f5056
dualsourcecache: add a cache name
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2375
diff
changeset
|
347 _cachename = 'evo-ext-obscache' # used for error message |
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
|
348 |
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
|
349 def __init__(self, repo): |
2357
f787f5406a98
obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2356
diff
changeset
|
350 super(obscache, self).__init__() |
f787f5406a98
obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2356
diff
changeset
|
351 self._ondiskkey = None |
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
|
352 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
|
353 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
|
354 |
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
|
355 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
|
356 """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
|
357 |
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
|
358 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
|
359 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
|
360 |
2357
f787f5406a98
obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2356
diff
changeset
|
361 def clear(self, reset=False): |
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
|
362 """invalidate the cache content""" |
2357
f787f5406a98
obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2356
diff
changeset
|
363 super(obscache, self).clear(reset=reset) |
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 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
|
365 |
2356
d5de0529a48f
obscache: extract the actual data update in a dedicated function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2355
diff
changeset
|
366 def _updatefrom(self, repo, revs, obsmarkers): |
d5de0529a48f
obscache: extract the actual data update in a dedicated function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2355
diff
changeset
|
367 if revs: |
d5de0529a48f
obscache: extract the actual data update in a dedicated function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2355
diff
changeset
|
368 self._updaterevs(repo, revs) |
d5de0529a48f
obscache: extract the actual data update in a dedicated function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2355
diff
changeset
|
369 if obsmarkers: |
d5de0529a48f
obscache: extract the actual data update in a dedicated function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2355
diff
changeset
|
370 self._updatemarkers(repo, obsmarkers) |
d5de0529a48f
obscache: extract the actual data update in a dedicated function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2355
diff
changeset
|
371 |
2326
72853bade853
obscache: extract code to update from new revision
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2325
diff
changeset
|
372 def _updaterevs(self, repo, revs): |
72853bade853
obscache: extract code to update from new revision
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2325
diff
changeset
|
373 """update the cache with new revisions |
72853bade853
obscache: extract code to update from new revision
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2325
diff
changeset
|
374 |
72853bade853
obscache: extract code to update from new revision
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2325
diff
changeset
|
375 Newly added changeset might be affected by obsolescence markers |
2329
3bb8382fc4cb
obscache: update some documentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2328
diff
changeset
|
376 we already have locally. So we needs to have some global |
3bb8382fc4cb
obscache: update some documentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2328
diff
changeset
|
377 knowledge about the markers to handle that question. |
2326
72853bade853
obscache: extract code to update from new revision
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2325
diff
changeset
|
378 |
2329
3bb8382fc4cb
obscache: update some documentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2328
diff
changeset
|
379 Right now this requires parsing all markers in the obsstore. We could |
3bb8382fc4cb
obscache: update some documentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2328
diff
changeset
|
380 imagine using various optimisation (eg: another cache, network |
3bb8382fc4cb
obscache: update some documentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2328
diff
changeset
|
381 exchange, etc). |
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
|
382 |
2330
d72c8c1f09e2
obscache: document a possible way forward to skipping obsstore parsing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2329
diff
changeset
|
383 A possible approach to this is to build a set of all node used as |
d72c8c1f09e2
obscache: document a possible way forward to skipping obsstore parsing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2329
diff
changeset
|
384 precursors in `obsstore._obscandidate`. If markers are not loaded yet, |
d72c8c1f09e2
obscache: document a possible way forward to skipping obsstore parsing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2329
diff
changeset
|
385 we could initialize it by doing a quick scan through the obsstore data |
d72c8c1f09e2
obscache: document a possible way forward to skipping obsstore parsing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2329
diff
changeset
|
386 and filling a (pre-sized) set. Doing so would be much faster than |
d72c8c1f09e2
obscache: document a possible way forward to skipping obsstore parsing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2329
diff
changeset
|
387 parsing all the obsmarkers since we would access less data, not create |
d72c8c1f09e2
obscache: document a possible way forward to skipping obsstore parsing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2329
diff
changeset
|
388 any object beside the nodes and not have to decode any complex data. |
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
|
389 |
2329
3bb8382fc4cb
obscache: update some documentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2328
diff
changeset
|
390 For now we stick to the simpler approach of paying the |
2326
72853bade853
obscache: extract code to update from new revision
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2325
diff
changeset
|
391 performance cost on new changesets. |
72853bade853
obscache: extract code to update from new revision
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2325
diff
changeset
|
392 """ |
72853bade853
obscache: extract code to update from new revision
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2325
diff
changeset
|
393 node = repo.changelog.node |
72853bade853
obscache: extract code to update from new revision
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2325
diff
changeset
|
394 succs = repo.obsstore.successors |
72853bade853
obscache: extract code to update from new revision
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2325
diff
changeset
|
395 for r in revs: |
72853bade853
obscache: extract code to update from new revision
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2325
diff
changeset
|
396 if node(r) in succs: |
72853bade853
obscache: extract code to update from new revision
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2325
diff
changeset
|
397 val = 1 |
72853bade853
obscache: extract code to update from new revision
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2325
diff
changeset
|
398 else: |
72853bade853
obscache: extract code to update from new revision
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2325
diff
changeset
|
399 val = 0 |
72853bade853
obscache: extract code to update from new revision
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2325
diff
changeset
|
400 self._data.append(val) |
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
|
401 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
|
402 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
|
403 |
2327
6b751daad348
obscache: extract _updatemarkers code into its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2326
diff
changeset
|
404 def _updatemarkers(self, repo, obsmarkers): |
6b751daad348
obscache: extract _updatemarkers code into its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2326
diff
changeset
|
405 """update the cache with new markers""" |
6b751daad348
obscache: extract _updatemarkers code into its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2326
diff
changeset
|
406 rev = repo.changelog.nodemap.get |
6b751daad348
obscache: extract _updatemarkers code into its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2326
diff
changeset
|
407 for m in obsmarkers: |
6b751daad348
obscache: extract _updatemarkers code into its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2326
diff
changeset
|
408 r = rev(m[0]) |
6b751daad348
obscache: extract _updatemarkers code into its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2326
diff
changeset
|
409 if r is not None: |
6b751daad348
obscache: extract _updatemarkers code into its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2326
diff
changeset
|
410 self._data[r] = 1 |
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
|
411 |
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
|
412 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
|
413 """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
|
414 |
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
|
415 # XXX it happens that the obsstore is (buggilly) always up to date on disk |
2309
9f09cabe679e
obscache: skip writing to disk if the data did not changed
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2308
diff
changeset
|
416 if self._cachekey is None or self._cachekey == self._ondiskkey: |
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
|
417 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
|
418 |
2316
35a548465647
compat: drop the context manager used to write the cache file
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2315
diff
changeset
|
419 cachefile = repo.vfs(self._filepath, 'w', atomictemp=True) |
35a548465647
compat: drop the context manager used to write the cache file
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2315
diff
changeset
|
420 headerdata = struct.pack(self._headerformat, *self._cachekey) |
35a548465647
compat: drop the context manager used to write the cache file
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2315
diff
changeset
|
421 cachefile.write(headerdata) |
35a548465647
compat: drop the context manager used to write the cache file
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2315
diff
changeset
|
422 cachefile.write(self._data) |
35a548465647
compat: drop the context manager used to write the cache file
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2315
diff
changeset
|
423 cachefile.close() |
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
|
424 |
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
|
425 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
|
426 """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
|
427 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
|
428 |
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
|
429 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
|
430 if not data: |
2353
393cbaf0d294
obcache: move empty on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2352
diff
changeset
|
431 self._cachekey = self.emptykey |
2309
9f09cabe679e
obscache: skip writing to disk if the data did not changed
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2308
diff
changeset
|
432 self._data = bytearray() |
9f09cabe679e
obscache: skip writing to disk if the data did not changed
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2308
diff
changeset
|
433 else: |
9f09cabe679e
obscache: skip writing to disk if the data did not changed
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2308
diff
changeset
|
434 headersize = struct.calcsize(self._headerformat) |
9f09cabe679e
obscache: skip writing to disk if the data did not changed
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2308
diff
changeset
|
435 self._cachekey = struct.unpack(self._headerformat, data[:headersize]) |
9f09cabe679e
obscache: skip writing to disk if the data did not changed
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2308
diff
changeset
|
436 self._data = bytearray(data[headersize:]) |
9f09cabe679e
obscache: skip writing to disk if the data did not changed
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2308
diff
changeset
|
437 self._ondiskkey = self._cachekey |
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
|
438 |
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
|
439 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
|
440 """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
|
441 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
|
442 repo = repo.unfiltered() |
2315
e16f6bef5848
compat: make obscache code compatible with Mercurial version prior to 4.2
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2309
diff
changeset
|
443 if util.safehasattr(repo._phasecache, 'getrevset'): |
e16f6bef5848
compat: make obscache code compatible with Mercurial version prior to 4.2
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2309
diff
changeset
|
444 notpublic = repo._phasecache.getrevset(repo, (phases.draft, phases.secret)) |
e16f6bef5848
compat: make obscache code compatible with Mercurial version prior to 4.2
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2309
diff
changeset
|
445 else: |
e16f6bef5848
compat: make obscache code compatible with Mercurial version prior to 4.2
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2309
diff
changeset
|
446 # < hg-4.2 compat |
e16f6bef5848
compat: make obscache code compatible with Mercurial version prior to 4.2
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2309
diff
changeset
|
447 notpublic = repo.revs("not public()") |
2298
8199204274f0
perf: use the cache to compute the obsolete set.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2297
diff
changeset
|
448 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
|
449 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
|
450 # Since we warm the cache at the end of every transaction, the cache |
2329
3bb8382fc4cb
obscache: update some documentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2328
diff
changeset
|
451 # should be up to date. However a non-enabled client might have touched |
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
|
452 # 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
|
453 # |
01efebff13ec
obscache: skip the cache entirely if not up to date
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2298
diff
changeset
|
454 # 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
|
455 # 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
|
456 # 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
|
457 # |
01efebff13ec
obscache: skip the cache entirely if not up to date
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2298
diff
changeset
|
458 # 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
|
459 # load the obsstore anyway. Once loaded, hitting the obsstore directly |
2329
3bb8382fc4cb
obscache: update some documentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2328
diff
changeset
|
460 # will be about as fast... |
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
|
461 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
|
462 if repo.currenttransaction() is None: |
2379
3593442d4a0e
obshashrange: adds blackbox usage in tests
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2376
diff
changeset
|
463 repo.ui.log('evoext-cache', |
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
|
464 '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
|
465 '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
|
466 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
|
467 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
|
468 else: |
2329
3bb8382fc4cb
obscache: update some documentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2328
diff
changeset
|
469 # If a transaction is open, it is worthwhile to update and use |
3bb8382fc4cb
obscache: update some documentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2328
diff
changeset
|
470 # the cache, the lock prevent race and it will be written on |
3bb8382fc4cb
obscache: update some documentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2328
diff
changeset
|
471 # disk when the transaction close. |
2304
2f15090712fe
obscache: still update and use the cache during transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2303
diff
changeset
|
472 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
|
473 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
|
474 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
|
475 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
|
476 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
|
477 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
|
478 |
8199204274f0
perf: use the cache to compute the obsolete set.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2297
diff
changeset
|
479 @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
|
480 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
|
481 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
|
482 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
|
483 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
|
484 |
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
|
485 @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
|
486 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
|
487 |
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
|
488 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
|
489 |
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
|
490 @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
|
491 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
|
492 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
|
493 self.obsstore.obscache.clear() |
2367
3be45918c7b5
evolve: fixing obscache invalidation
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
2316
diff
changeset
|
494 super(obscacherepo, self).destroyed() |
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
|
495 |
2297
32cdcf493567
perf: warm the cache after all transactions
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2296
diff
changeset
|
496 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
|
497 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
|
498 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
|
499 |
32cdcf493567
perf: warm the cache after all transactions
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2296
diff
changeset
|
500 def _warmcache(tr): |
32cdcf493567
perf: warm the cache after all transactions
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2296
diff
changeset
|
501 repo = reporef() |
32cdcf493567
perf: warm the cache after all transactions
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2296
diff
changeset
|
502 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
|
503 return |
2303
8534400111fd
obscache: warm the cache in all cases
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2302
diff
changeset
|
504 repo = repo.unfiltered() |
2329
3bb8382fc4cb
obscache: update some documentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2328
diff
changeset
|
505 # As pointed in 'obscache.update', we could have the changelog |
3bb8382fc4cb
obscache: update some documentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2328
diff
changeset
|
506 # and the obsstore in charge of updating the cache when new |
3bb8382fc4cb
obscache: update some documentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2328
diff
changeset
|
507 # items goes it. The tranaction logic would then only be |
3bb8382fc4cb
obscache: update some documentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2328
diff
changeset
|
508 # involved for the 'pending' and final writing on disk. |
2303
8534400111fd
obscache: warm the cache in all cases
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2302
diff
changeset
|
509 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
|
510 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
|
511 |
32cdcf493567
perf: warm the cache after all transactions
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2296
diff
changeset
|
512 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
|
513 return tr |
32cdcf493567
perf: warm the cache after all transactions
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2296
diff
changeset
|
514 |
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
|
515 repo.__class__ = obscacherepo |