author | Pierre-Yves David <pierre-yves.david@octobus.net> |
Wed, 03 May 2017 18:33:53 +0200 | |
changeset 2325 | 04a0eda7dea9 |
parent 2316 | 35a548465647 |
child 2326 | 72853bade853 |
permissions | -rw-r--r-- |
2294
75996eafab43
perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
1 |
# Code dedicated to an cache around obsolescence property |
75996eafab43
perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
2 |
# |
75996eafab43
perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
3 |
# This module content aims at being upstreamed. |
75996eafab43
perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
4 |
# |
75996eafab43
perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
5 |
# Copyright 2017 Pierre-Yves David <pierre-yves.david@ens-lyon.org> |
75996eafab43
perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
6 |
# |
75996eafab43
perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
7 |
# This software may be used and distributed according to the terms of the |
75996eafab43
perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
8 |
# GNU General Public License version 2 or any later version. |
75996eafab43
perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
9 |
|
2296
d6584ce58030
perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2295
diff
changeset
|
10 |
import hashlib |
d6584ce58030
perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2295
diff
changeset
|
11 |
import struct |
d6584ce58030
perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2295
diff
changeset
|
12 |
import weakref |
d6584ce58030
perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2295
diff
changeset
|
13 |
import errno |
d6584ce58030
perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2295
diff
changeset
|
14 |
|
d6584ce58030
perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2295
diff
changeset
|
15 |
from mercurial import ( |
d6584ce58030
perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2295
diff
changeset
|
16 |
localrepo, |
d6584ce58030
perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2295
diff
changeset
|
17 |
obsolete, |
d6584ce58030
perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2295
diff
changeset
|
18 |
phases, |
d6584ce58030
perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2295
diff
changeset
|
19 |
node, |
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
|
20 |
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
|
21 |
) |
d6584ce58030
perf: 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 |
|
2294
75996eafab43
perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
23 |
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
|
24 |
exthelper, |
75996eafab43
perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
25 |
) |
75996eafab43
perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
26 |
|
75996eafab43
perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
27 |
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
|
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 |
try: |
75996eafab43
perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
30 |
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
|
31 |
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
|
32 |
# 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
|
33 |
# |
75996eafab43
perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
34 |
# 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
|
35 |
# 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
|
36 |
# 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
|
37 |
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
|
38 |
|
75996eafab43
perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
39 |
# 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
|
40 |
@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
|
41 |
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
|
42 |
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
|
43 |
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
|
44 |
|
75996eafab43
perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
45 |
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
|
46 |
|
75996eafab43
perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
47 |
_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
|
48 |
|
75996eafab43
perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
49 |
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
|
50 |
"""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
|
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 |
'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
|
53 |
'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
|
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 |
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
|
56 |
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
|
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 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
|
59 |
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
|
60 |
# default value |
b33bc2f37e89
obscache: have the obsstore fix empty file cachekey
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2305
diff
changeset
|
61 |
obsstoresize = 0 |
b33bc2f37e89
obscache: have the obsstore fix empty file cachekey
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2305
diff
changeset
|
62 |
keydata = '' |
b33bc2f37e89
obscache: have the obsstore fix empty file cachekey
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2305
diff
changeset
|
63 |
# 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
|
64 |
try: |
75996eafab43
perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
65 |
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
|
66 |
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
|
67 |
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
|
68 |
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
|
69 |
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
|
70 |
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
|
71 |
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
|
72 |
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
|
73 |
if actualsize: |
b33bc2f37e89
obscache: have the obsstore fix empty file cachekey
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2305
diff
changeset
|
74 |
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
|
75 |
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
|
76 |
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
|
77 |
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
|
78 |
raise |
2306
b33bc2f37e89
obscache: have the obsstore fix empty file cachekey
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2305
diff
changeset
|
79 |
key = hashlib.sha1(keydata).digest() |
b33bc2f37e89
obscache: have the obsstore fix empty file cachekey
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2305
diff
changeset
|
80 |
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
|
81 |
|
75996eafab43
perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
82 |
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
|
83 |
|
75996eafab43
perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
84 |
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
|
85 |
|
2307
0d2e0e8e76f6
obscache: set a valid "empty" cache key if the cache is missing
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2306
diff
changeset
|
86 |
emptykey = (node.nullrev, node.nullid, 0, 0, node.nullid) |
0d2e0e8e76f6
obscache: set a valid "empty" cache key if the cache is missing
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2306
diff
changeset
|
87 |
|
2295
017b971ba28f
perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2294
diff
changeset
|
88 |
def getcachekey(repo): |
017b971ba28f
perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2294
diff
changeset
|
89 |
"""get a cache key covering the changesets and obsmarkers content |
017b971ba28f
perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2294
diff
changeset
|
90 |
|
017b971ba28f
perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2294
diff
changeset
|
91 |
IT contains the following data. Combined with 'upgradeneeded' it allows to |
017b971ba28f
perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2294
diff
changeset
|
92 |
do iterative upgrade for cache depending of theses two data. |
017b971ba28f
perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2294
diff
changeset
|
93 |
|
017b971ba28f
perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2294
diff
changeset
|
94 |
The cache key parts are" |
017b971ba28f
perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2294
diff
changeset
|
95 |
- tip-rev, |
017b971ba28f
perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2294
diff
changeset
|
96 |
- tip-node, |
017b971ba28f
perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2294
diff
changeset
|
97 |
- obsstore-length (nb markers), |
017b971ba28f
perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2294
diff
changeset
|
98 |
- obsstore-file-size (in bytes), |
017b971ba28f
perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2294
diff
changeset
|
99 |
- obsstore "cache key" |
017b971ba28f
perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2294
diff
changeset
|
100 |
""" |
017b971ba28f
perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2294
diff
changeset
|
101 |
assert repo.filtername is None |
017b971ba28f
perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2294
diff
changeset
|
102 |
cl = repo.changelog |
017b971ba28f
perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2294
diff
changeset
|
103 |
index, key = repo.obsstore.cachekey() |
017b971ba28f
perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2294
diff
changeset
|
104 |
tiprev = len(cl) - 1 |
017b971ba28f
perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2294
diff
changeset
|
105 |
return (tiprev, |
017b971ba28f
perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2294
diff
changeset
|
106 |
cl.node(tiprev), |
017b971ba28f
perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2294
diff
changeset
|
107 |
len(repo.obsstore), |
017b971ba28f
perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2294
diff
changeset
|
108 |
index, |
017b971ba28f
perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2294
diff
changeset
|
109 |
key) |
017b971ba28f
perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2294
diff
changeset
|
110 |
|
017b971ba28f
perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2294
diff
changeset
|
111 |
def upgradeneeded(repo, key): |
017b971ba28f
perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2294
diff
changeset
|
112 |
"""return (valid, start-rev, start-obs-idx) |
017b971ba28f
perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2294
diff
changeset
|
113 |
|
017b971ba28f
perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2294
diff
changeset
|
114 |
'valid': is "False" if older cache value needs invalidation, |
017b971ba28f
perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2294
diff
changeset
|
115 |
|
017b971ba28f
perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2294
diff
changeset
|
116 |
'start-rev': first revision not in the cache. None if cache is up to date, |
017b971ba28f
perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2294
diff
changeset
|
117 |
|
017b971ba28f
perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2294
diff
changeset
|
118 |
'start-obs-idx': index of the first obs-markers not in the cache. None is |
017b971ba28f
perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2294
diff
changeset
|
119 |
up to date. |
017b971ba28f
perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2294
diff
changeset
|
120 |
""" |
017b971ba28f
perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2294
diff
changeset
|
121 |
|
017b971ba28f
perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2294
diff
changeset
|
122 |
# XXX ideally, this function would return a bounded amount of changeset and |
017b971ba28f
perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2294
diff
changeset
|
123 |
# obsmarkers and the associated new cache key. Otherwise we are exposed to |
017b971ba28f
perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2294
diff
changeset
|
124 |
# a race condition between the time the cache is updated and the new cache |
017b971ba28f
perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2294
diff
changeset
|
125 |
# key is computed. (however, we do not want to compute the full new cache |
017b971ba28f
perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2294
diff
changeset
|
126 |
# key in all case because we want to skip reading the obsstore content. We |
017b971ba28f
perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2294
diff
changeset
|
127 |
# could have a smarter implementation here. |
017b971ba28f
perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2294
diff
changeset
|
128 |
# |
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
|
129 |
# In pratice the cache is only updated after each transaction within a |
2295
017b971ba28f
perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2294
diff
changeset
|
130 |
# lock. So we should be fine. We could enforce this with a new repository |
017b971ba28f
perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2294
diff
changeset
|
131 |
# requirement (or fix the race, that is not too hard). |
017b971ba28f
perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2294
diff
changeset
|
132 |
invalid = (False, 0, 0) |
017b971ba28f
perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2294
diff
changeset
|
133 |
if key is None: |
017b971ba28f
perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2294
diff
changeset
|
134 |
return invalid |
017b971ba28f
perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2294
diff
changeset
|
135 |
|
017b971ba28f
perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2294
diff
changeset
|
136 |
### Is the cache valid ? |
017b971ba28f
perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2294
diff
changeset
|
137 |
keytiprev, keytipnode, keyobslength, keyobssize, keyobskey = key |
017b971ba28f
perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2294
diff
changeset
|
138 |
# check for changelog strip |
017b971ba28f
perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2294
diff
changeset
|
139 |
cl = repo.changelog |
017b971ba28f
perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2294
diff
changeset
|
140 |
tiprev = len(cl) - 1 |
017b971ba28f
perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2294
diff
changeset
|
141 |
if (tiprev < keytiprev |
017b971ba28f
perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2294
diff
changeset
|
142 |
or cl.node(keytiprev) != keytipnode): |
017b971ba28f
perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2294
diff
changeset
|
143 |
return invalid |
017b971ba28f
perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2294
diff
changeset
|
144 |
# check for obsstore strip |
017b971ba28f
perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2294
diff
changeset
|
145 |
obssize, obskey = repo.obsstore.cachekey(index=keyobssize) |
017b971ba28f
perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2294
diff
changeset
|
146 |
if obskey != keyobskey: |
017b971ba28f
perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2294
diff
changeset
|
147 |
return invalid |
017b971ba28f
perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2294
diff
changeset
|
148 |
|
017b971ba28f
perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2294
diff
changeset
|
149 |
### cache is valid, is there anything to update |
017b971ba28f
perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2294
diff
changeset
|
150 |
|
017b971ba28f
perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2294
diff
changeset
|
151 |
# any new changesets ? |
017b971ba28f
perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2294
diff
changeset
|
152 |
startrev = None |
017b971ba28f
perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2294
diff
changeset
|
153 |
if keytiprev < tiprev: |
017b971ba28f
perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2294
diff
changeset
|
154 |
startrev = keytiprev + 1 |
017b971ba28f
perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2294
diff
changeset
|
155 |
|
017b971ba28f
perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2294
diff
changeset
|
156 |
# any new markers |
017b971ba28f
perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2294
diff
changeset
|
157 |
startidx = None |
017b971ba28f
perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2294
diff
changeset
|
158 |
if keyobssize < obssize: |
017b971ba28f
perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2294
diff
changeset
|
159 |
startidx = keyobslength |
017b971ba28f
perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2294
diff
changeset
|
160 |
|
017b971ba28f
perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2294
diff
changeset
|
161 |
return True, startrev, startidx |
2296
d6584ce58030
perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2295
diff
changeset
|
162 |
|
d6584ce58030
perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2295
diff
changeset
|
163 |
class obscache(object): |
d6584ce58030
perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2295
diff
changeset
|
164 |
"""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
|
165 |
|
d6584ce58030
perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2295
diff
changeset
|
166 |
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
|
167 |
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
|
168 |
"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
|
169 |
|
d6584ce58030
perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2295
diff
changeset
|
170 |
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
|
171 |
|
d6584ce58030
perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2295
diff
changeset
|
172 |
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
|
173 |
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
|
174 |
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
|
175 |
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
|
176 |
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
|
177 |
|
d6584ce58030
perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2295
diff
changeset
|
178 |
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
|
179 |
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
|
180 |
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
|
181 |
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
|
182 |
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
|
183 |
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
|
184 |
|
d6584ce58030
perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2295
diff
changeset
|
185 |
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
|
186 |
|
d6584ce58030
perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2295
diff
changeset
|
187 |
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
|
188 |
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
|
189 |
'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
|
190 |
|
d6584ce58030
perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2295
diff
changeset
|
191 |
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
|
192 |
|
d6584ce58030
perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2295
diff
changeset
|
193 |
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
|
194 |
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
|
195 |
""" |
d6584ce58030
perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2295
diff
changeset
|
196 |
|
d6584ce58030
perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2295
diff
changeset
|
197 |
_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
|
198 |
_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
|
199 |
|
d6584ce58030
perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2295
diff
changeset
|
200 |
def __init__(self, repo): |
d6584ce58030
perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2295
diff
changeset
|
201 |
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
|
202 |
# The cache key parts are" |
d6584ce58030
perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2295
diff
changeset
|
203 |
# - tip-rev, |
d6584ce58030
perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2295
diff
changeset
|
204 |
# - tip-node, |
d6584ce58030
perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2295
diff
changeset
|
205 |
# - obsstore-length (nb markers), |
d6584ce58030
perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2295
diff
changeset
|
206 |
# - obsstore-file-size (in bytes), |
d6584ce58030
perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2295
diff
changeset
|
207 |
# - obsstore "cache key" |
d6584ce58030
perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2295
diff
changeset
|
208 |
self._cachekey = None |
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
|
209 |
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
|
210 |
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
|
211 |
|
d6584ce58030
perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2295
diff
changeset
|
212 |
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
|
213 |
"""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
|
214 |
|
d6584ce58030
perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2295
diff
changeset
|
215 |
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
|
216 |
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
|
217 |
|
d6584ce58030
perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2295
diff
changeset
|
218 |
def clear(self): |
d6584ce58030
perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2295
diff
changeset
|
219 |
"""invalidate the cache content""" |
d6584ce58030
perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2295
diff
changeset
|
220 |
self._cachekey = None |
d6584ce58030
perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2295
diff
changeset
|
221 |
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
|
222 |
|
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
|
223 |
def uptodate(self, repo): |
2301
54b2fddbc2f5
obscache: load the disk data before checking is the cache is up to date
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2300
diff
changeset
|
224 |
if self._cachekey is None: |
54b2fddbc2f5
obscache: load the disk data before checking is the cache is up to date
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2300
diff
changeset
|
225 |
self.load(repo) |
2300
01efebff13ec
obscache: skip the cache entirely if not up to date
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2298
diff
changeset
|
226 |
valid, startrev, startidx = upgradeneeded(repo, self._cachekey) |
01efebff13ec
obscache: skip the cache entirely if not up to date
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2298
diff
changeset
|
227 |
return (valid and startrev is None and startidx is None) |
01efebff13ec
obscache: skip the cache entirely if not up to date
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2298
diff
changeset
|
228 |
|
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 |
def update(self, repo): |
d6584ce58030
perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2295
diff
changeset
|
230 |
"""Iteratively update the cache with new repository data""" |
d6584ce58030
perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2295
diff
changeset
|
231 |
# If we do not have any data, try loading from disk |
d6584ce58030
perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2295
diff
changeset
|
232 |
if self._cachekey is None: |
d6584ce58030
perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2295
diff
changeset
|
233 |
self.load(repo) |
d6584ce58030
perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2295
diff
changeset
|
234 |
|
d6584ce58030
perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2295
diff
changeset
|
235 |
valid, startrev, startidx = upgradeneeded(repo, self._cachekey) |
d6584ce58030
perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2295
diff
changeset
|
236 |
if not valid: |
d6584ce58030
perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2295
diff
changeset
|
237 |
self.clear() |
d6584ce58030
perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2295
diff
changeset
|
238 |
|
d6584ce58030
perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2295
diff
changeset
|
239 |
if startrev is None and startidx is None: |
d6584ce58030
perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2295
diff
changeset
|
240 |
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
|
241 |
|
2325
04a0eda7dea9
obscache: move assert earlier in the code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2316
diff
changeset
|
242 |
# checks we never run 'update' without a lock |
04a0eda7dea9
obscache: move assert earlier in the code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2316
diff
changeset
|
243 |
# |
04a0eda7dea9
obscache: move assert earlier in the code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2316
diff
changeset
|
244 |
# There are a potential race condition otherwise, since the repo |
04a0eda7dea9
obscache: move assert earlier in the code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2316
diff
changeset
|
245 |
# "might" have changed side the cache update above. However, this code |
04a0eda7dea9
obscache: move assert earlier in the code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2316
diff
changeset
|
246 |
# will only be running in a lock so we ignore the issue for now. |
04a0eda7dea9
obscache: move assert earlier in the code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2316
diff
changeset
|
247 |
# |
04a0eda7dea9
obscache: move assert earlier in the code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2316
diff
changeset
|
248 |
# Lift this limitation, 'upgradeneeded' should return a bounded amount |
04a0eda7dea9
obscache: move assert earlier in the code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2316
diff
changeset
|
249 |
# of changeset and markers to read with their associated cachekey. see |
04a0eda7dea9
obscache: move assert earlier in the code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2316
diff
changeset
|
250 |
# 'upgradeneeded' for detail. |
04a0eda7dea9
obscache: move assert earlier in the code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2316
diff
changeset
|
251 |
assert repo._currentlock(repo._lockref) is not None |
04a0eda7dea9
obscache: move assert earlier in the code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2316
diff
changeset
|
252 |
|
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
|
253 |
# process the new changesets |
d6584ce58030
perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2295
diff
changeset
|
254 |
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
|
255 |
if startrev is not None: |
d6584ce58030
perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2295
diff
changeset
|
256 |
node = cl.node |
d6584ce58030
perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2295
diff
changeset
|
257 |
# Note: |
d6584ce58030
perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2295
diff
changeset
|
258 |
# |
d6584ce58030
perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2295
diff
changeset
|
259 |
# Newly added changeset might be affected by obsolescence markers |
d6584ce58030
perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2295
diff
changeset
|
260 |
# we already have locally. So we needs to have soem global |
d6584ce58030
perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2295
diff
changeset
|
261 |
# knowledge about the markers to handle that question. Right this |
d6584ce58030
perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2295
diff
changeset
|
262 |
# requires parsing all markers in the obsstore. However, we could |
d6584ce58030
perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2295
diff
changeset
|
263 |
# imagine using various optimisation (eg: bloom filter, other on |
d6584ce58030
perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2295
diff
changeset
|
264 |
# disk cache) to remove this full parsing. |
d6584ce58030
perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2295
diff
changeset
|
265 |
# |
d6584ce58030
perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2295
diff
changeset
|
266 |
# For now we stick to the simpler approach or paying the |
d6584ce58030
perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2295
diff
changeset
|
267 |
# performance cost on new changesets. |
d6584ce58030
perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2295
diff
changeset
|
268 |
succs = repo.obsstore.successors |
d6584ce58030
perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2295
diff
changeset
|
269 |
for r in cl.revs(startrev): |
d6584ce58030
perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2295
diff
changeset
|
270 |
if node(r) in succs: |
d6584ce58030
perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2295
diff
changeset
|
271 |
val = 1 |
d6584ce58030
perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2295
diff
changeset
|
272 |
else: |
d6584ce58030
perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2295
diff
changeset
|
273 |
val = 0 |
d6584ce58030
perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2295
diff
changeset
|
274 |
self._data.append(val) |
d6584ce58030
perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2295
diff
changeset
|
275 |
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
|
276 |
|
d6584ce58030
perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2295
diff
changeset
|
277 |
# process the new obsmarkers |
d6584ce58030
perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2295
diff
changeset
|
278 |
if startidx is not None: |
d6584ce58030
perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2295
diff
changeset
|
279 |
rev = cl.nodemap.get |
d6584ce58030
perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2295
diff
changeset
|
280 |
markers = repo.obsstore._all |
d6584ce58030
perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2295
diff
changeset
|
281 |
# Note: |
d6584ce58030
perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2295
diff
changeset
|
282 |
# |
d6584ce58030
perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2295
diff
changeset
|
283 |
# There are no actually needs to load the full obsstore here, |
d6584ce58030
perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2295
diff
changeset
|
284 |
# since we only read the latest ones. We do it for simplicity in |
d6584ce58030
perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2295
diff
changeset
|
285 |
# the first implementation. Loading the full obsstore has a |
d6584ce58030
perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2295
diff
changeset
|
286 |
# performance cost and should go away in this case too. We have |
d6584ce58030
perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2295
diff
changeset
|
287 |
# two simples options for that: |
d6584ce58030
perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2295
diff
changeset
|
288 |
# |
d6584ce58030
perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2295
diff
changeset
|
289 |
# 1) provide and API to start reading markers from a byte offset |
d6584ce58030
perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2295
diff
changeset
|
290 |
# (we have that data in the cache key) |
d6584ce58030
perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2295
diff
changeset
|
291 |
# |
d6584ce58030
perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2295
diff
changeset
|
292 |
# 2) directly update the cache at a lower level, in the code |
d6584ce58030
perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2295
diff
changeset
|
293 |
# responsible for adding a markers. |
d6584ce58030
perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2295
diff
changeset
|
294 |
# |
d6584ce58030
perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2295
diff
changeset
|
295 |
# Option 2 is probably a bit more invasive, but more solid on the long run |
d6584ce58030
perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2295
diff
changeset
|
296 |
|
d6584ce58030
perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2295
diff
changeset
|
297 |
for i in xrange(startidx, len(repo.obsstore)): |
d6584ce58030
perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2295
diff
changeset
|
298 |
r = rev(markers[i][0]) |
d6584ce58030
perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2295
diff
changeset
|
299 |
# If markers affect a newly added nodes, it would have been |
d6584ce58030
perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2295
diff
changeset
|
300 |
# caught in the previous loop, (so we skip < startrev) |
d6584ce58030
perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2295
diff
changeset
|
301 |
if r is not None and (startrev is None or r < startrev): |
d6584ce58030
perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2295
diff
changeset
|
302 |
self._data[r] = 1 |
d6584ce58030
perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2295
diff
changeset
|
303 |
|
d6584ce58030
perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2295
diff
changeset
|
304 |
self._cachekey = getcachekey(repo) |
d6584ce58030
perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2295
diff
changeset
|
305 |
|
d6584ce58030
perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2295
diff
changeset
|
306 |
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
|
307 |
"""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
|
308 |
|
d6584ce58030
perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2295
diff
changeset
|
309 |
# 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
|
310 |
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
|
311 |
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
|
312 |
|
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
|
313 |
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
|
314 |
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
|
315 |
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
|
316 |
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
|
317 |
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
|
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 |
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
|
320 |
"""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
|
321 |
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
|
322 |
|
d6584ce58030
perf: 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 |
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
|
324 |
if not data: |
2307
0d2e0e8e76f6
obscache: set a valid "empty" cache key if the cache is missing
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2306
diff
changeset
|
325 |
self._cachekey = 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
|
326 |
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
|
327 |
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
|
328 |
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
|
329 |
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
|
330 |
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
|
331 |
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
|
332 |
|
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
|
333 |
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
|
334 |
"""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
|
335 |
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
|
336 |
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
|
337 |
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
|
338 |
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
|
339 |
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
|
340 |
# < 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
|
341 |
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
|
342 |
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
|
343 |
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
|
344 |
# Since we warm the cache at the end of every transaction, the cache |
01efebff13ec
obscache: skip the cache entirely if not up to date
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2298
diff
changeset
|
345 |
# should be up to date. However a non-enabled client might have touced |
01efebff13ec
obscache: skip the cache entirely if not up to date
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2298
diff
changeset
|
346 |
# 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
|
347 |
# |
01efebff13ec
obscache: skip the cache entirely if not up to date
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2298
diff
changeset
|
348 |
# 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
|
349 |
# 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
|
350 |
# 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
|
351 |
# |
01efebff13ec
obscache: skip the cache entirely if not up to date
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2298
diff
changeset
|
352 |
# 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
|
353 |
# load the obsstore anyway. Once loaded, hitting the obsstore directly |
01efebff13ec
obscache: skip the cache entirely if not up to date
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2298
diff
changeset
|
354 |
# will be about as fast.. |
01efebff13ec
obscache: skip the cache entirely if not up to date
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2298
diff
changeset
|
355 |
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
|
356 |
if repo.currenttransaction() is None: |
2305
a786240c95bd
obscache: log case where the cache is not up to date
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2304
diff
changeset
|
357 |
repo.ui.log('evoext-obscache', |
a786240c95bd
obscache: log case where the cache is not up to date
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2304
diff
changeset
|
358 |
'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
|
359 |
'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
|
360 |
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
|
361 |
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
|
362 |
else: |
2f15090712fe
obscache: still update and use the cache during transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2303
diff
changeset
|
363 |
# If a transaction is open, it is worthwhile to update and use the |
2f15090712fe
obscache: still update and use the cache during transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2303
diff
changeset
|
364 |
# cache as it will be written on disk when the transaction close. |
2f15090712fe
obscache: still update and use the cache during transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2303
diff
changeset
|
365 |
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
|
366 |
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
|
367 |
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
|
368 |
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
|
369 |
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
|
370 |
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
|
371 |
|
8199204274f0
perf: use the cache to compute the obsolete set.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2297
diff
changeset
|
372 |
@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
|
373 |
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
|
374 |
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
|
375 |
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
|
376 |
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
|
377 |
|
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
|
378 |
@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
|
379 |
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
|
380 |
|
d6584ce58030
perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2295
diff
changeset
|
381 |
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
|
382 |
|
d6584ce58030
perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2295
diff
changeset
|
383 |
@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
|
384 |
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
|
385 |
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
|
386 |
self.obsstore.obscache.clear() |
d6584ce58030
perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2295
diff
changeset
|
387 |
|
2297
32cdcf493567
perf: warm the cache after all transactions
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2296
diff
changeset
|
388 |
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
|
389 |
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
|
390 |
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
|
391 |
|
32cdcf493567
perf: warm the cache after all transactions
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2296
diff
changeset
|
392 |
def _warmcache(tr): |
32cdcf493567
perf: warm the cache after all transactions
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2296
diff
changeset
|
393 |
repo = reporef() |
32cdcf493567
perf: warm the cache after all transactions
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2296
diff
changeset
|
394 |
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
|
395 |
return |
2303
8534400111fd
obscache: warm the cache in all cases
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2302
diff
changeset
|
396 |
repo = repo.unfiltered() |
8534400111fd
obscache: warm the cache in all cases
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2302
diff
changeset
|
397 |
# As pointed in 'obscache.update', we could have the |
8534400111fd
obscache: warm the cache in all cases
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2302
diff
changeset
|
398 |
# changelog and the obsstore in charge of updating the |
8534400111fd
obscache: warm the cache in all cases
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2302
diff
changeset
|
399 |
# cache when new items goes it. The tranaction logic would |
8534400111fd
obscache: warm the cache in all cases
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2302
diff
changeset
|
400 |
# then only be involved for the 'pending' and final saving |
8534400111fd
obscache: warm the cache in all cases
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2302
diff
changeset
|
401 |
# logic. |
8534400111fd
obscache: warm the cache in all cases
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2302
diff
changeset
|
402 |
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
|
403 |
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
|
404 |
|
32cdcf493567
perf: warm the cache after all transactions
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2296
diff
changeset
|
405 |
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
|
406 |
return tr |
32cdcf493567
perf: warm the cache after all transactions
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
2296
diff
changeset
|
407 |
|
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
|
408 |
repo.__class__ = obscacherepo |