Skip to content
Snippets Groups Projects
Commit cf49e54e authored by Pierre-Yves David's avatar Pierre-Yves David :octopus:
Browse files

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
parent 6085b7f1
No related branches found
No related tags found
No related merge requests found
......@@ -21,9 +21,10 @@
requirements,
revlog,
scmutil,
store,
util,
vfs as vfsmod,
)
from ..revlogutils import nodemap
......@@ -24,11 +25,11 @@
util,
vfs as vfsmod,
)
from ..revlogutils import nodemap
def _revlogfrompath(repo, path):
def _revlogfrompath(repo, rl_type, path):
"""Obtain a revlog from a repo path.
An instance of the appropriate class is returned.
"""
......@@ -31,6 +32,6 @@
"""Obtain a revlog from a repo path.
An instance of the appropriate class is returned.
"""
if path == b'00changelog.i':
if rl_type & store.FILEFLAGS_CHANGELOG:
return changelog.changelog(repo.svfs)
......@@ -36,7 +37,9 @@
return changelog.changelog(repo.svfs)
elif path.endswith(b'00manifest.i'):
mandir = path[: -len(b'00manifest.i')]
elif rl_type & store.FILEFLAGS_MANIFESTLOG:
mandir = b''
if b'/' in path:
mandir = path.rsplit(b'/', 1)[0]
return manifest.manifestrevlog(
repo.nodeconstants, repo.svfs, tree=mandir
)
else:
......@@ -39,8 +42,9 @@
return manifest.manifestrevlog(
repo.nodeconstants, repo.svfs, tree=mandir
)
else:
# reverse of "/".join(("data", path + ".i"))
return filelog.filelog(repo.svfs, path[5:-2])
# drop the extension and the `data/` prefix
path = path.rsplit(b'.', 1)[0].split(b'/', 1)[1]
return filelog.filelog(repo.svfs, path)
......@@ -45,6 +49,6 @@
def _copyrevlog(tr, destrepo, oldrl, unencodedname):
def _copyrevlog(tr, destrepo, oldrl, rl_type, unencodedname):
"""copy all relevant files for `oldrl` into `destrepo` store
Files are copied "as is" without any transformation. The copy is performed
......@@ -52,7 +56,7 @@
content is compatible with format of the destination repository.
"""
oldrl = getattr(oldrl, '_revlog', oldrl)
newrl = _revlogfrompath(destrepo, unencodedname)
newrl = _revlogfrompath(destrepo, rl_type, unencodedname)
newrl = getattr(newrl, '_revlog', newrl)
oldvfs = oldrl.opener
......@@ -70,10 +74,7 @@
if copydata:
util.copyfile(olddata, newdata)
if not (
unencodedname.endswith(b'00changelog.i')
or unencodedname.endswith(b'00manifest.i')
):
if rl_type & store.FILEFLAGS_FILELOG:
destrepo.svfs.fncache.add(unencodedname)
if copydata:
destrepo.svfs.fncache.add(unencodedname[:-2] + b'.d')
......@@ -107,10 +108,10 @@
return sidedatacompanion
def matchrevlog(revlogfilter, entry):
def matchrevlog(revlogfilter, rl_type):
"""check if a revlog is selected for cloning.
In other words, are there any updates which need to be done on revlog
or it can be blindly copied.
The store entry is checked against the passed filter"""
......@@ -111,8 +112,8 @@
"""check if a revlog is selected for cloning.
In other words, are there any updates which need to be done on revlog
or it can be blindly copied.
The store entry is checked against the passed filter"""
if entry.endswith(b'00changelog.i'):
if rl_type & store.FILEFLAGS_CHANGELOG:
return UPGRADE_CHANGELOG in revlogfilter
......@@ -118,3 +119,3 @@
return UPGRADE_CHANGELOG in revlogfilter
elif entry.endswith(b'00manifest.i'):
elif rl_type & store.FILEFLAGS_MANIFESTLOG:
return UPGRADE_MANIFEST in revlogfilter
......@@ -120,4 +121,5 @@
return UPGRADE_MANIFEST in revlogfilter
assert rl_type & store.FILEFLAGS_FILELOG
return UPGRADE_FILELOGS in revlogfilter
......@@ -126,6 +128,7 @@
dstrepo,
tr,
old_revlog,
rl_type,
unencoded,
upgrade_op,
sidedatacompanion,
......@@ -133,7 +136,7 @@
):
""" returns the new revlog object created"""
newrl = None
if matchrevlog(upgrade_op.revlogs_to_process, unencoded):
if matchrevlog(upgrade_op.revlogs_to_process, rl_type):
ui.note(
_(b'cloning %d revisions from %s\n') % (len(old_revlog), unencoded)
)
......@@ -137,7 +140,7 @@
ui.note(
_(b'cloning %d revisions from %s\n') % (len(old_revlog), unencoded)
)
newrl = _revlogfrompath(dstrepo, unencoded)
newrl = _revlogfrompath(dstrepo, rl_type, unencoded)
old_revlog.clone(
tr,
newrl,
......@@ -149,5 +152,5 @@
else:
msg = _(b'blindly copying %s containing %i revisions\n')
ui.note(msg % (unencoded, len(old_revlog)))
_copyrevlog(tr, dstrepo, old_revlog, unencoded)
_copyrevlog(tr, dstrepo, old_revlog, rl_type, unencoded)
......@@ -153,5 +156,5 @@
newrl = _revlogfrompath(dstrepo, unencoded)
newrl = _revlogfrompath(dstrepo, rl_type, unencoded)
return newrl
......@@ -192,7 +195,7 @@
# Perform a pass to collect metadata. This validates we can open all
# source files and allows a unified progress bar to be displayed.
for revlog_type, unencoded, encoded, size in alldatafiles:
if not unencoded.endswith(b'.i'):
for rl_type, unencoded, encoded, size in alldatafiles:
if not rl_type & store.FILEFLAGS_REVLOG_MAIN:
continue
......@@ -197,6 +200,6 @@
continue
rl = _revlogfrompath(srcrepo, unencoded)
rl = _revlogfrompath(srcrepo, rl_type, unencoded)
info = rl.storageinfo(
exclusivefiles=True,
......@@ -213,8 +216,8 @@
srcrawsize += rawsize
# This is for the separate progress bars.
if isinstance(rl, changelog.changelog):
changelogs[unencoded] = rl
if rl_type & store.FILEFLAGS_CHANGELOG:
changelogs[unencoded] = (rl_type, rl)
crevcount += len(rl)
csrcsize += datasize
crawsize += rawsize
......@@ -218,9 +221,9 @@
crevcount += len(rl)
csrcsize += datasize
crawsize += rawsize
elif isinstance(rl, manifest.manifestrevlog):
manifests[unencoded] = rl
elif rl_type & store.FILEFLAGS_MANIFESTLOG:
manifests[unencoded] = (rl_type, rl)
mcount += 1
mrevcount += len(rl)
msrcsize += datasize
mrawsize += rawsize
......@@ -223,9 +226,9 @@
mcount += 1
mrevcount += len(rl)
msrcsize += datasize
mrawsize += rawsize
elif isinstance(rl, filelog.filelog):
filelogs[unencoded] = rl
elif rl_type & store.FILEFLAGS_FILELOG:
filelogs[unencoded] = (rl_type, rl)
fcount += 1
frevcount += len(rl)
fsrcsize += datasize
......@@ -270,9 +273,9 @@
)
)
progress = srcrepo.ui.makeprogress(_(b'file revisions'), total=frevcount)
for unencoded, oldrl in sorted(filelogs.items()):
for unencoded, (rl_type, oldrl) in sorted(filelogs.items()):
newrl = _perform_clone(
ui,
dstrepo,
tr,
oldrl,
......@@ -274,8 +277,9 @@
newrl = _perform_clone(
ui,
dstrepo,
tr,
oldrl,
rl_type,
unencoded,
upgrade_op,
sidedatacompanion,
......@@ -309,9 +313,9 @@
progress = srcrepo.ui.makeprogress(
_(b'manifest revisions'), total=mrevcount
)
for unencoded, oldrl in sorted(manifests.items()):
for unencoded, (rl_type, oldrl) in sorted(manifests.items()):
newrl = _perform_clone(
ui,
dstrepo,
tr,
oldrl,
......@@ -313,8 +317,9 @@
newrl = _perform_clone(
ui,
dstrepo,
tr,
oldrl,
rl_type,
unencoded,
upgrade_op,
sidedatacompanion,
......@@ -347,9 +352,9 @@
progress = srcrepo.ui.makeprogress(
_(b'changelog revisions'), total=crevcount
)
for unencoded, oldrl in sorted(changelogs.items()):
for unencoded, (rl_type, oldrl) in sorted(changelogs.items()):
newrl = _perform_clone(
ui,
dstrepo,
tr,
oldrl,
......@@ -351,8 +356,9 @@
newrl = _perform_clone(
ui,
dstrepo,
tr,
oldrl,
rl_type,
unencoded,
upgrade_op,
sidedatacompanion,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment