p4fastimporter: optimize sync import - do not write dup filelogs

Differential Revision: https://phabricator.intern.facebook.com/D5966218
This commit is contained in:
Zhihui Huang 2017-10-11 17:49:48 -07:00
parent b49a8c00b7
commit ba9a6009ff
3 changed files with 46 additions and 22 deletions

View File

@ -348,7 +348,7 @@ def p4syncimport(ui, repo, client, **opts):
if len(repo) == 0:
raise error.Abort(_('p4 sync commit does not support empty repo yet.'))
p1ctx, __, __ = startfrom(ui, repo, opts)
p1ctx, startcl, __ = startfrom(ui, repo, opts)
# Fail if the specified client does not exist
if not p4.exists_client(client):
@ -362,6 +362,8 @@ def p4syncimport(ui, repo, client, **opts):
ui.note(_('Latest change list number %s\n') % latestcl)
p4filelogs = p4.get_filelogs_at_cl(client, latestcl)
p4filelogs = sorted(p4filelogs)
newp4filelogs, reusep4filelogs = importer.get_filelogs_to_sync(
client, repo, p1ctx, startcl - 1, p4filelogs)
# sync import.
with repo.wlock(), repo.lock():
@ -371,9 +373,9 @@ def p4syncimport(ui, repo, client, **opts):
largefileslist = []
tr = repo.transaction('syncimport')
try:
for p4fl in p4filelogs:
for p4fl, localname in newp4filelogs:
bfi = importer.SyncFileImporter(
ui, repo, client, latestcl, p4fl)
ui, repo, client, latestcl, p4fl, localfile=localname)
# Create hg filelog
fileflags, largefiles, oldtiprev, newtiprev = bfi.create(tr)
fileinfo[p4fl.depotfile] = {
@ -387,7 +389,7 @@ def p4syncimport(ui, repo, client, **opts):
clog = importer.SyncChangeManifestImporter(
ui, repo, client, latestcl, p1ctx=p1ctx)
revisions = []
for cl, hgnode in clog.creategen(tr, fileinfo):
for cl, hgnode in clog.creategen(tr, fileinfo, reusep4filelogs):
revisions.append((cl, hex(hgnode)))
if opts.get('bookmark'):

View File

@ -175,7 +175,7 @@ class SyncChangeManifestImporter(ChangeManifestImporter):
self._cl = cl
self._p1ctx = p1ctx
def creategen(self, tr, fileinfo):
def creategen(self, tr, fileinfo, reusefilelogs):
mrevlog = self._repo.manifestlog._revlog
clog = self._repo.changelog
cp1 = self._p1ctx.node()
@ -184,6 +184,7 @@ class SyncChangeManifestImporter(ChangeManifestImporter):
mp1 = p1.manifestnode()
mp2 = nullid
mf = manifest.manifestdict()
p1mf = p1.manifest().copy()
changed = []
for info in fileinfo.values():
@ -191,6 +192,9 @@ class SyncChangeManifestImporter(ChangeManifestImporter):
baserev = info['baserev']
mf[localname] = self._repo.file(localname).node(baserev)
changed.append(localname)
for localfile in reusefilelogs:
mf[localfile] = p1mf[localfile]
linkrev = len(self._repo)
oldmp1 = mp1
mp1 = mrevlog.addrevision(mf.text(mrevlog._usemanifestv2), tr,
@ -440,16 +444,20 @@ class FileImporter(object):
return fileflags, largefiles, origlen, newlen
class SyncFileImporter(FileImporter):
def __init__(self, ui, repo, client, cl, p4filelog):
def __init__(self, ui, repo, client, cl, p4filelog, localfile=None):
self._ui = ui
self._repo = repo
self._client = client
self._cl = cl
self._p4filelog = p4filelog
self._localfile = localfile
@util.propertycache
def relpath(self):
return relpath(self._client, self._p4filelog.depotfile)
if self._localfile:
return self._localfile
else:
return relpath(self._client, self._p4filelog.depotfile)
def create(self, tr):
assert tr is not None

View File

@ -90,21 +90,42 @@ Sync Import
updating the branch cache
1 revision, 4 file(s) imported.
Verify
$ hg verify
checking changesets
checking manifests
crosschecking files in changesets and manifests
checking files
5 files, 3 changesets, 7 total revisions
$ hg update master
4 files updated, 0 files merged, 0 files removed, 0 files unresolved
(activating bookmark master)
Sync Import without New Changes
$ hg p4syncimport --bookmark master --debug -P $P4ROOT hg-p4-import
incremental import from changelist: 4, node: * (glob)
Latest change list number 3
running a sync import.
writing filelog: 0a738da2fcb2, p1 861f64b39056, linkrev 3, 4 bytes, src: *, path: Main/b (glob)
writing filelog: 825765709d02, p1 149da44f2a4e, linkrev 3, 2 bytes, src: *, path: Main/c (glob)
writing filelog: c3bd1155d122, p1 6b67ccefd5ce, linkrev 3, 2 bytes, src: *, path: Main/d/e (glob)
writing filelog: 7fd4bac0fb3a, p1 0973eb1b2ecc, linkrev 3, 2 bytes, src: *, path: Main/d/f/g (glob)
changelist 3: writing manifest. node: c11fdd72fcbf p1: f0ca72fbd536 p2: 000000000000 linkrev: 3
changelist 3: writing manifest. node: 2037a8409eae p1: f0ca72fbd536 p2: 000000000000 linkrev: 3
changelist 3: writing changelog: p4fastimport synchronizing client view
writing bookmark
updating the branch cache
1 revision, 4 file(s) imported.
1 revision, 0 file(s) imported.
Verify
$ hg verify
checking changesets
checking manifests
crosschecking files in changesets and manifests
checking files
5 files, 4 changesets, 7 total revisions
$ hg update master
0 files updated, 0 files merged, 0 files removed, 0 files unresolved
Fast Import after Sync Import
@ -120,17 +141,10 @@ Verify
checking manifests
crosschecking files in changesets and manifests
checking files
5 files, 4 changesets, 11 total revisions
5 files, 4 changesets, 7 total revisions
$ hg update master
4 files updated, 0 files merged, 0 files removed, 0 files unresolved
(activating bookmark master)
$ hg manifest -r master
Main/b
Main/c
Main/d/e
Main/d/f/g
0 files updated, 0 files merged, 0 files removed, 0 files unresolved
End Test
stopping the p4 server