##// END OF EJS Templates
sidedata: move sidedata-related utils to the dedicated module...
Raphaël Gomès -
r47848:3aab2330 default
parent child Browse files
Show More
@@ -7,7 +7,6 b''
7 7
8 8 from __future__ import absolute_import
9 9
10 import collections
11 10 import os
12 11 import struct
13 12 import weakref
@@ -301,7 +300,7 b' class cg1unpacker(object):'
301 300 and srctype == b'pull'
302 301 )
303 302 if adding_sidedata:
304 sidedata_helpers = get_sidedata_helpers(
303 sidedata_helpers = sidedatamod.get_sidedata_helpers(
305 304 repo,
306 305 sidedata_categories or set(),
307 306 pull=True,
@@ -1073,7 +1072,9 b' class cgpacker(object):'
1073 1072 # TODO a better approach would be for the strip bundle to
1074 1073 # correctly advertise its sidedata categories directly.
1075 1074 remote_sidedata = repo._wanted_sidedata
1076 sidedata_helpers = get_sidedata_helpers(repo, remote_sidedata)
1075 sidedata_helpers = sidedatamod.get_sidedata_helpers(
1076 repo, remote_sidedata
1077 )
1077 1078
1078 1079 clstate, deltas = self._generatechangelog(
1079 1080 cl,
@@ -1940,24 +1941,3 b' def _addchangegroupfiles('
1940 1941 )
1941 1942
1942 1943 return revisions, files
1943
1944
1945 def get_sidedata_helpers(repo, remote_sd_categories, pull=False):
1946 # Computers for computing sidedata on-the-fly
1947 sd_computers = collections.defaultdict(list)
1948 # Computers for categories to remove from sidedata
1949 sd_removers = collections.defaultdict(list)
1950 to_generate = remote_sd_categories - repo._wanted_sidedata
1951 to_remove = repo._wanted_sidedata - remote_sd_categories
1952 if pull:
1953 to_generate, to_remove = to_remove, to_generate
1954
1955 for revlog_kind, computers in repo._sidedata_computers.items():
1956 for category, computer in computers.items():
1957 if category in to_generate:
1958 sd_computers[revlog_kind].append(computer)
1959 if category in to_remove:
1960 sd_removers[revlog_kind].append(computer)
1961
1962 sidedata_helpers = (repo, sd_computers, sd_removers)
1963 return sidedata_helpers
@@ -49,7 +49,6 b' from . import ('
49 49 match as matchmod,
50 50 mergestate as mergestatemod,
51 51 mergeutil,
52 metadata as metadatamod,
53 52 namespaces,
54 53 narrowspec,
55 54 obsolete,
@@ -90,6 +89,7 b' from .utils import ('
90 89 from .revlogutils import (
91 90 concurrency_checker as revlogchecker,
92 91 constants as revlogconst,
92 sidedata as sidedatamod,
93 93 )
94 94
95 95 release = lockmod.release
@@ -1407,7 +1407,7 b' class localrepository(object):'
1407 1407
1408 1408 self._wanted_sidedata = set()
1409 1409 self._sidedata_computers = {}
1410 metadatamod.set_sidedata_spec_for_repo(self)
1410 sidedatamod.set_sidedata_spec_for_repo(self)
1411 1411
1412 1412 def _getvfsward(self, origfunc):
1413 1413 """build a ward for self.vfs"""
@@ -14,12 +14,10 b' import struct'
14 14 from .node import nullrev
15 15 from . import (
16 16 error,
17 requirements as requirementsmod,
18 17 util,
19 18 )
20 19
21 20 from .revlogutils import (
22 constants as revlogconst,
23 21 flagutil as sidedataflag,
24 22 sidedata as sidedatamod,
25 23 )
@@ -824,18 +822,6 b' def copies_sidedata_computer(repo, revlo'
824 822 return sidedata, (flags_to_add, 0)
825 823
826 824
827 def set_sidedata_spec_for_repo(repo):
828 if requirementsmod.COPIESSDC_REQUIREMENT in repo.requirements:
829 repo.register_wanted_sidedata(sidedatamod.SD_FILES)
830 repo.register_sidedata_computer(
831 revlogconst.KIND_CHANGELOG,
832 sidedatamod.SD_FILES,
833 (sidedatamod.SD_FILES,),
834 copies_sidedata_computer,
835 sidedataflag.REVIDX_HASCOPIESINFO,
836 )
837
838
839 825 def _sidedata_worker(srcrepo, revs_queue, sidedata_queue, tokens):
840 826 """The function used by worker precomputing sidedata
841 827
@@ -2781,7 +2781,7 b' class revlog(object):'
2781 2781 text, sidedata = self._revisiondata(rev)
2782 2782
2783 2783 if sidedata_helpers is not None:
2784 (sidedata, new_flags) = storageutil.run_sidedata_helpers(
2784 (sidedata, new_flags) = sidedatautil.run_sidedata_helpers(
2785 2785 self, sidedata_helpers, sidedata, rev
2786 2786 )
2787 2787 flags = flags | new_flags[0] & ~new_flags[1]
@@ -2811,7 +2811,7 b' class revlog(object):'
2811 2811 sidedata = self.sidedata(rev)
2812 2812
2813 2813 if sidedata_helpers is not None:
2814 (sidedata, new_flags) = storageutil.run_sidedata_helpers(
2814 (sidedata, new_flags) = sidedatautil.run_sidedata_helpers(
2815 2815 self, sidedata_helpers, sidedata, rev
2816 2816 )
2817 2817 flags = flags | new_flags[0] & ~new_flags[1]
@@ -3089,7 +3089,7 b' class revlog(object):'
3089 3089 current_offset = fp.tell()
3090 3090 for rev in range(startrev, endrev + 1):
3091 3091 entry = self.index[rev]
3092 new_sidedata, flags = storageutil.run_sidedata_helpers(
3092 new_sidedata, flags = sidedatautil.run_sidedata_helpers(
3093 3093 store=self,
3094 3094 sidedata_helpers=helpers,
3095 3095 sidedata={},
@@ -32,9 +32,11 b' the concept.'
32 32
33 33 from __future__ import absolute_import
34 34
35 import collections
35 36 import struct
36 37
37 from .. import error
38 from .. import error, requirements as requirementsmod
39 from ..revlogutils import constants, flagutil
38 40 from ..utils import hashutil
39 41
40 42 ## sidedata type constant
@@ -91,3 +93,63 b' def deserialize_sidedata(blob):'
91 93 sidedata[key] = entrytext
92 94 dataoffset = nextdataoffset
93 95 return sidedata
96
97
98 def get_sidedata_helpers(repo, remote_sd_categories, pull=False):
99 # Computers for computing sidedata on-the-fly
100 sd_computers = collections.defaultdict(list)
101 # Computers for categories to remove from sidedata
102 sd_removers = collections.defaultdict(list)
103 to_generate = remote_sd_categories - repo._wanted_sidedata
104 to_remove = repo._wanted_sidedata - remote_sd_categories
105 if pull:
106 to_generate, to_remove = to_remove, to_generate
107
108 for revlog_kind, computers in repo._sidedata_computers.items():
109 for category, computer in computers.items():
110 if category in to_generate:
111 sd_computers[revlog_kind].append(computer)
112 if category in to_remove:
113 sd_removers[revlog_kind].append(computer)
114
115 sidedata_helpers = (repo, sd_computers, sd_removers)
116 return sidedata_helpers
117
118
119 def run_sidedata_helpers(store, sidedata_helpers, sidedata, rev):
120 """Returns the sidedata for the given revision after running through
121 the given helpers.
122 - `store`: the revlog this applies to (changelog, manifest, or filelog
123 instance)
124 - `sidedata_helpers`: see `storageutil.emitrevisions`
125 - `sidedata`: previous sidedata at the given rev, if any
126 - `rev`: affected rev of `store`
127 """
128 repo, sd_computers, sd_removers = sidedata_helpers
129 kind = store.revlog_kind
130 flags_to_add = 0
131 flags_to_remove = 0
132 for _keys, sd_computer, _flags in sd_computers.get(kind, []):
133 sidedata, flags = sd_computer(repo, store, rev, sidedata)
134 flags_to_add |= flags[0]
135 flags_to_remove |= flags[1]
136 for keys, _computer, flags in sd_removers.get(kind, []):
137 for key in keys:
138 sidedata.pop(key, None)
139 flags_to_remove |= flags
140 return sidedata, (flags_to_add, flags_to_remove)
141
142
143 def set_sidedata_spec_for_repo(repo):
144 # prevent cycle metadata -> revlogutils.sidedata -> metadata
145 from .. import metadata
146
147 if requirementsmod.COPIESSDC_REQUIREMENT in repo.requirements:
148 repo.register_wanted_sidedata(SD_FILES)
149 repo.register_sidedata_computer(
150 constants.KIND_CHANGELOG,
151 SD_FILES,
152 (SD_FILES,),
153 metadata.copies_sidedata_computer,
154 flagutil.REVIDX_HASCOPIESINFO,
155 )
@@ -12,7 +12,6 b' import stat'
12 12 from ..i18n import _
13 13 from ..pycompat import getattr
14 14 from .. import (
15 changegroup,
16 15 changelog,
17 16 error,
18 17 filelog,
@@ -45,7 +44,7 b' def get_sidedata_helpers(srcrepo, dstrep'
45 44 flagutil.REVIDX_HASCOPIESINFO,
46 45 replace=True,
47 46 )
48 return changegroup.get_sidedata_helpers(srcrepo, dstrepo._wanted_sidedata)
47 return sidedatamod.get_sidedata_helpers(srcrepo, dstrepo._wanted_sidedata)
49 48
50 49
51 50 def _revlogfrompath(repo, rl_type, path):
@@ -499,7 +499,7 b' def emitrevisions('
499 499 sidedata_flags = (0, 0)
500 500 if sidedata_helpers:
501 501 old_sidedata = store.sidedata(rev)
502 sidedata, sidedata_flags = run_sidedata_helpers(
502 sidedata, sidedata_flags = sidedatamod.run_sidedata_helpers(
503 503 store=store,
504 504 sidedata_helpers=sidedata_helpers,
505 505 sidedata=old_sidedata,
@@ -532,30 +532,6 b' def emitrevisions('
532 532 prevrev = rev
533 533
534 534
535 def run_sidedata_helpers(store, sidedata_helpers, sidedata, rev):
536 """Returns the sidedata for the given revision after running through
537 the given helpers.
538 - `store`: the revlog this applies to (changelog, manifest, or filelog
539 instance)
540 - `sidedata_helpers`: see `storageutil.emitrevisions`
541 - `sidedata`: previous sidedata at the given rev, if any
542 - `rev`: affected rev of `store`
543 """
544 repo, sd_computers, sd_removers = sidedata_helpers
545 kind = store.revlog_kind
546 flags_to_add = 0
547 flags_to_remove = 0
548 for _keys, sd_computer, _flags in sd_computers.get(kind, []):
549 sidedata, flags = sd_computer(repo, store, rev, sidedata)
550 flags_to_add |= flags[0]
551 flags_to_remove |= flags[1]
552 for keys, _computer, flags in sd_removers.get(kind, []):
553 for key in keys:
554 sidedata.pop(key, None)
555 flags_to_remove |= flags
556 return sidedata, (flags_to_add, flags_to_remove)
557
558
559 535 def deltaiscensored(delta, baserev, baselenfn):
560 536 """Determine if a delta represents censored revision data.
561 537
@@ -12,7 +12,6 b' import struct'
12 12
13 13 from mercurial.node import nullrev
14 14 from mercurial import (
15 changegroup,
16 15 extensions,
17 16 requirements,
18 17 revlog,
@@ -88,7 +87,7 b' def wrapget_sidedata_helpers(orig, srcre'
88 87 )
89 88 dstrepo.register_wanted_sidedata(b"whatever")
90 89
91 return changegroup.get_sidedata_helpers(srcrepo, dstrepo._wanted_sidedata)
90 return sidedata.get_sidedata_helpers(srcrepo, dstrepo._wanted_sidedata)
92 91
93 92
94 93 def extsetup(ui):
General Comments 0
You need to be logged in to leave comments. Login now