comparison mercurial/upgrade_utils/engine.py @ 46896:cf49e54ef965

upgrade: take advantage of the new information returned by `store.walk` Before this change the upgrade code had to analyse filename to process them directly. Lets keep that logic private to the store and more to a more robust explicit approach. Differential Revision: https://phab.mercurial-scm.org/D10316
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Tue, 06 Apr 2021 10:38:11 +0200
parents 6085b7f1536d
children 1c52d77d7861
comparison
equal deleted inserted replaced
46895:6085b7f1536d 46896:cf49e54ef965
19 metadata, 19 metadata,
20 pycompat, 20 pycompat,
21 requirements, 21 requirements,
22 revlog, 22 revlog,
23 scmutil, 23 scmutil,
24 store,
24 util, 25 util,
25 vfs as vfsmod, 26 vfs as vfsmod,
26 ) 27 )
27 from ..revlogutils import nodemap 28 from ..revlogutils import nodemap
28 29
29 30
30 def _revlogfrompath(repo, path): 31 def _revlogfrompath(repo, rl_type, path):
31 """Obtain a revlog from a repo path. 32 """Obtain a revlog from a repo path.
32 33
33 An instance of the appropriate class is returned. 34 An instance of the appropriate class is returned.
34 """ 35 """
35 if path == b'00changelog.i': 36 if rl_type & store.FILEFLAGS_CHANGELOG:
36 return changelog.changelog(repo.svfs) 37 return changelog.changelog(repo.svfs)
37 elif path.endswith(b'00manifest.i'): 38 elif rl_type & store.FILEFLAGS_MANIFESTLOG:
38 mandir = path[: -len(b'00manifest.i')] 39 mandir = b''
40 if b'/' in path:
41 mandir = path.rsplit(b'/', 1)[0]
39 return manifest.manifestrevlog( 42 return manifest.manifestrevlog(
40 repo.nodeconstants, repo.svfs, tree=mandir 43 repo.nodeconstants, repo.svfs, tree=mandir
41 ) 44 )
42 else: 45 else:
43 # reverse of "/".join(("data", path + ".i")) 46 # drop the extension and the `data/` prefix
44 return filelog.filelog(repo.svfs, path[5:-2]) 47 path = path.rsplit(b'.', 1)[0].split(b'/', 1)[1]
45 48 return filelog.filelog(repo.svfs, path)
46 49
47 def _copyrevlog(tr, destrepo, oldrl, unencodedname): 50
51 def _copyrevlog(tr, destrepo, oldrl, rl_type, unencodedname):
48 """copy all relevant files for `oldrl` into `destrepo` store 52 """copy all relevant files for `oldrl` into `destrepo` store
49 53
50 Files are copied "as is" without any transformation. The copy is performed 54 Files are copied "as is" without any transformation. The copy is performed
51 without extra checks. Callers are responsible for making sure the copied 55 without extra checks. Callers are responsible for making sure the copied
52 content is compatible with format of the destination repository. 56 content is compatible with format of the destination repository.
53 """ 57 """
54 oldrl = getattr(oldrl, '_revlog', oldrl) 58 oldrl = getattr(oldrl, '_revlog', oldrl)
55 newrl = _revlogfrompath(destrepo, unencodedname) 59 newrl = _revlogfrompath(destrepo, rl_type, unencodedname)
56 newrl = getattr(newrl, '_revlog', newrl) 60 newrl = getattr(newrl, '_revlog', newrl)
57 61
58 oldvfs = oldrl.opener 62 oldvfs = oldrl.opener
59 newvfs = newrl.opener 63 newvfs = newrl.opener
60 oldindex = oldvfs.join(oldrl.indexfile) 64 oldindex = oldvfs.join(oldrl.indexfile)
68 util.copyfile(oldindex, newindex) 72 util.copyfile(oldindex, newindex)
69 copydata = oldrl.opener.exists(oldrl.datafile) 73 copydata = oldrl.opener.exists(oldrl.datafile)
70 if copydata: 74 if copydata:
71 util.copyfile(olddata, newdata) 75 util.copyfile(olddata, newdata)
72 76
73 if not ( 77 if rl_type & store.FILEFLAGS_FILELOG:
74 unencodedname.endswith(b'00changelog.i')
75 or unencodedname.endswith(b'00manifest.i')
76 ):
77 destrepo.svfs.fncache.add(unencodedname) 78 destrepo.svfs.fncache.add(unencodedname)
78 if copydata: 79 if copydata:
79 destrepo.svfs.fncache.add(unencodedname[:-2] + b'.d') 80 destrepo.svfs.fncache.add(unencodedname[:-2] + b'.d')
80 81
81 82
105 elif requirements.COPIESSDC_REQUIREMENT in removedreqs: 106 elif requirements.COPIESSDC_REQUIREMENT in removedreqs:
106 sidedatacompanion = metadata.getsidedataremover(srcrepo, dstrepo) 107 sidedatacompanion = metadata.getsidedataremover(srcrepo, dstrepo)
107 return sidedatacompanion 108 return sidedatacompanion
108 109
109 110
110 def matchrevlog(revlogfilter, entry): 111 def matchrevlog(revlogfilter, rl_type):
111 """check if a revlog is selected for cloning. 112 """check if a revlog is selected for cloning.
112 113
113 In other words, are there any updates which need to be done on revlog 114 In other words, are there any updates which need to be done on revlog
114 or it can be blindly copied. 115 or it can be blindly copied.
115 116
116 The store entry is checked against the passed filter""" 117 The store entry is checked against the passed filter"""
117 if entry.endswith(b'00changelog.i'): 118 if rl_type & store.FILEFLAGS_CHANGELOG:
118 return UPGRADE_CHANGELOG in revlogfilter 119 return UPGRADE_CHANGELOG in revlogfilter
119 elif entry.endswith(b'00manifest.i'): 120 elif rl_type & store.FILEFLAGS_MANIFESTLOG:
120 return UPGRADE_MANIFEST in revlogfilter 121 return UPGRADE_MANIFEST in revlogfilter
122 assert rl_type & store.FILEFLAGS_FILELOG
121 return UPGRADE_FILELOGS in revlogfilter 123 return UPGRADE_FILELOGS in revlogfilter
122 124
123 125
124 def _perform_clone( 126 def _perform_clone(
125 ui, 127 ui,
126 dstrepo, 128 dstrepo,
127 tr, 129 tr,
128 old_revlog, 130 old_revlog,
131 rl_type,
129 unencoded, 132 unencoded,
130 upgrade_op, 133 upgrade_op,
131 sidedatacompanion, 134 sidedatacompanion,
132 oncopiedrevision, 135 oncopiedrevision,
133 ): 136 ):
134 """ returns the new revlog object created""" 137 """ returns the new revlog object created"""
135 newrl = None 138 newrl = None
136 if matchrevlog(upgrade_op.revlogs_to_process, unencoded): 139 if matchrevlog(upgrade_op.revlogs_to_process, rl_type):
137 ui.note( 140 ui.note(
138 _(b'cloning %d revisions from %s\n') % (len(old_revlog), unencoded) 141 _(b'cloning %d revisions from %s\n') % (len(old_revlog), unencoded)
139 ) 142 )
140 newrl = _revlogfrompath(dstrepo, unencoded) 143 newrl = _revlogfrompath(dstrepo, rl_type, unencoded)
141 old_revlog.clone( 144 old_revlog.clone(
142 tr, 145 tr,
143 newrl, 146 newrl,
144 addrevisioncb=oncopiedrevision, 147 addrevisioncb=oncopiedrevision,
145 deltareuse=upgrade_op.delta_reuse_mode, 148 deltareuse=upgrade_op.delta_reuse_mode,
147 sidedatacompanion=sidedatacompanion, 150 sidedatacompanion=sidedatacompanion,
148 ) 151 )
149 else: 152 else:
150 msg = _(b'blindly copying %s containing %i revisions\n') 153 msg = _(b'blindly copying %s containing %i revisions\n')
151 ui.note(msg % (unencoded, len(old_revlog))) 154 ui.note(msg % (unencoded, len(old_revlog)))
152 _copyrevlog(tr, dstrepo, old_revlog, unencoded) 155 _copyrevlog(tr, dstrepo, old_revlog, rl_type, unencoded)
153 156
154 newrl = _revlogfrompath(dstrepo, unencoded) 157 newrl = _revlogfrompath(dstrepo, rl_type, unencoded)
155 return newrl 158 return newrl
156 159
157 160
158 def _clonerevlogs( 161 def _clonerevlogs(
159 ui, 162 ui,
190 changelogs = {} 193 changelogs = {}
191 filelogs = {} 194 filelogs = {}
192 195
193 # Perform a pass to collect metadata. This validates we can open all 196 # Perform a pass to collect metadata. This validates we can open all
194 # source files and allows a unified progress bar to be displayed. 197 # source files and allows a unified progress bar to be displayed.
195 for revlog_type, unencoded, encoded, size in alldatafiles: 198 for rl_type, unencoded, encoded, size in alldatafiles:
196 if not unencoded.endswith(b'.i'): 199 if not rl_type & store.FILEFLAGS_REVLOG_MAIN:
197 continue 200 continue
198 201
199 rl = _revlogfrompath(srcrepo, unencoded) 202 rl = _revlogfrompath(srcrepo, rl_type, unencoded)
200 203
201 info = rl.storageinfo( 204 info = rl.storageinfo(
202 exclusivefiles=True, 205 exclusivefiles=True,
203 revisionscount=True, 206 revisionscount=True,
204 trackedsize=True, 207 trackedsize=True,
211 214
212 srcsize += datasize 215 srcsize += datasize
213 srcrawsize += rawsize 216 srcrawsize += rawsize
214 217
215 # This is for the separate progress bars. 218 # This is for the separate progress bars.
216 if isinstance(rl, changelog.changelog): 219 if rl_type & store.FILEFLAGS_CHANGELOG:
217 changelogs[unencoded] = rl 220 changelogs[unencoded] = (rl_type, rl)
218 crevcount += len(rl) 221 crevcount += len(rl)
219 csrcsize += datasize 222 csrcsize += datasize
220 crawsize += rawsize 223 crawsize += rawsize
221 elif isinstance(rl, manifest.manifestrevlog): 224 elif rl_type & store.FILEFLAGS_MANIFESTLOG:
222 manifests[unencoded] = rl 225 manifests[unencoded] = (rl_type, rl)
223 mcount += 1 226 mcount += 1
224 mrevcount += len(rl) 227 mrevcount += len(rl)
225 msrcsize += datasize 228 msrcsize += datasize
226 mrawsize += rawsize 229 mrawsize += rawsize
227 elif isinstance(rl, filelog.filelog): 230 elif rl_type & store.FILEFLAGS_FILELOG:
228 filelogs[unencoded] = rl 231 filelogs[unencoded] = (rl_type, rl)
229 fcount += 1 232 fcount += 1
230 frevcount += len(rl) 233 frevcount += len(rl)
231 fsrcsize += datasize 234 fsrcsize += datasize
232 frawsize += rawsize 235 frawsize += rawsize
233 else: 236 else:
268 util.bytecount(fsrcsize), 271 util.bytecount(fsrcsize),
269 util.bytecount(frawsize), 272 util.bytecount(frawsize),
270 ) 273 )
271 ) 274 )
272 progress = srcrepo.ui.makeprogress(_(b'file revisions'), total=frevcount) 275 progress = srcrepo.ui.makeprogress(_(b'file revisions'), total=frevcount)
273 for unencoded, oldrl in sorted(filelogs.items()): 276 for unencoded, (rl_type, oldrl) in sorted(filelogs.items()):
274 newrl = _perform_clone( 277 newrl = _perform_clone(
275 ui, 278 ui,
276 dstrepo, 279 dstrepo,
277 tr, 280 tr,
278 oldrl, 281 oldrl,
282 rl_type,
279 unencoded, 283 unencoded,
280 upgrade_op, 284 upgrade_op,
281 sidedatacompanion, 285 sidedatacompanion,
282 oncopiedrevision, 286 oncopiedrevision,
283 ) 287 )
307 if progress: 311 if progress:
308 progress.complete() 312 progress.complete()
309 progress = srcrepo.ui.makeprogress( 313 progress = srcrepo.ui.makeprogress(
310 _(b'manifest revisions'), total=mrevcount 314 _(b'manifest revisions'), total=mrevcount
311 ) 315 )
312 for unencoded, oldrl in sorted(manifests.items()): 316 for unencoded, (rl_type, oldrl) in sorted(manifests.items()):
313 newrl = _perform_clone( 317 newrl = _perform_clone(
314 ui, 318 ui,
315 dstrepo, 319 dstrepo,
316 tr, 320 tr,
317 oldrl, 321 oldrl,
322 rl_type,
318 unencoded, 323 unencoded,
319 upgrade_op, 324 upgrade_op,
320 sidedatacompanion, 325 sidedatacompanion,
321 oncopiedrevision, 326 oncopiedrevision,
322 ) 327 )
345 if progress: 350 if progress:
346 progress.complete() 351 progress.complete()
347 progress = srcrepo.ui.makeprogress( 352 progress = srcrepo.ui.makeprogress(
348 _(b'changelog revisions'), total=crevcount 353 _(b'changelog revisions'), total=crevcount
349 ) 354 )
350 for unencoded, oldrl in sorted(changelogs.items()): 355 for unencoded, (rl_type, oldrl) in sorted(changelogs.items()):
351 newrl = _perform_clone( 356 newrl = _perform_clone(
352 ui, 357 ui,
353 dstrepo, 358 dstrepo,
354 tr, 359 tr,
355 oldrl, 360 oldrl,
361 rl_type,
356 unencoded, 362 unencoded,
357 upgrade_op, 363 upgrade_op,
358 sidedatacompanion, 364 sidedatacompanion,
359 oncopiedrevision, 365 oncopiedrevision,
360 ) 366 )