Index: hgext3rd/p4fastimport/__init__.py =================================================================== --- hgext3rd/p4fastimport/__init__.py +++ hgext3rd/p4fastimport/__init__.py @@ -34,7 +34,7 @@ filetransaction as ftrmod ) -from .util import runworker, lastcl, decodefileflags +from .util import runworker, lastcl, getcl, decodefileflags from mercurial.i18n import _ from mercurial.node import short, hex @@ -337,9 +337,9 @@ 'p4syncimport', [('P', 'path', '.', _('path to the local depot store'), _('PATH')), ('B', 'bookmark', '', _('bookmark to set'), _('NAME'))], - _('[-P PATH] client [-B NAME] bookmarkname'), + _('[-P PATH] [-B NAME] oldclient newclient'), ) -def p4syncimport(ui, repo, client, **opts): +def p4syncimport(ui, repo, oldclient, newclient, **opts): if opts.get('bookmark'): scmutil.checknewlabel(repo, opts['bookmark'], 'bookmark') @@ -349,19 +349,31 @@ p1ctx, startcl, __ = startfrom(ui, repo, opts) # Fail if the specified client does not exist - if not p4.exists_client(client): - raise error.Abort(_('p4 client %s does not exist.') % client) + if not p4.exists_client(oldclient): + raise error.Abort(_('p4 client %s does not exist.') % oldclient) + if not p4.exists_client(newclient): + raise error.Abort(_('p4 client %s does not exist.') % newclient) # Get a list of files that we will have to import - latestcl = p4.get_latest_cl(client) + oldcl = p4.get_latest_cl(oldclient) + latestcl = p4.get_latest_cl(newclient) + lastimportedcl = getcl(p1ctx) if latestcl is None: - raise error.Abort(_('Cannot find latest p4 changelist number.')) + raise error.Abort(_('cannot find latest p4 changelist number')) + ui.debug('%r (current client) %r (requested client) ' + '%r (latest imported)\n' % (oldcl, latestcl, lastimportedcl)) + if oldcl != lastimportedcl: + # Consider running p4fastimport from here + raise error.Abort(_('repository must contain most recent changes')) - ui.note(_('Latest change list number %s\n') % latestcl) - p4filelogs = p4.get_filelogs_at_cl(client, latestcl) + ui.note(_('latest change list number %s\n') % latestcl) + p4filelogs = p4.get_filelogs_at_cl(newclient, latestcl) p4filelogs = sorted(p4filelogs) newp4filelogs, reusep4filelogs = importer.get_filelogs_to_sync( - client, repo, p1ctx, startcl - 1, p4filelogs) + newclient, repo, p1ctx, startcl - 1, p4filelogs) + + if not newp4filelogs and not reusep4filelogs: + raise error.Abort(_('nothing to import.')) # sync import. with repo.wlock(), repo.lock(): @@ -373,7 +385,8 @@ try: for p4fl, localname in newp4filelogs: bfi = importer.SyncFileImporter( - ui, repo, client, latestcl, p4fl, localfile=localname) + ui, repo, newclient, latestcl, p4fl, + localfile=localname) # Create hg filelog fileflags, largefiles, oldtiprev, newtiprev = bfi.create(tr) fileinfo[p4fl.depotfile] = { @@ -385,7 +398,7 @@ count += 1 # Generate manifest and changelog clog = importer.SyncChangeManifestImporter( - ui, repo, client, latestcl, p1ctx=p1ctx) + ui, repo, newclient, latestcl, p1ctx=p1ctx) revisions = [] for cl, hgnode in clog.creategen(tr, fileinfo, reusep4filelogs): revisions.append((cl, hex(hgnode))) Index: hgext3rd/p4fastimport/importer.py =================================================================== --- hgext3rd/p4fastimport/importer.py +++ hgext3rd/p4fastimport/importer.py @@ -31,10 +31,6 @@ return p4.decodefilename(filename) def get_filelogs_to_sync(client, repo, p1ctx, cl, p4filelogs): - latestcl = p4.get_latest_cl(client) - if latestcl > cl or latestcl is None: - p4filelogslist = [(p4fl, None) for p4fl in p4filelogs] - return p4filelogslist, [] p1 = repo[p1ctx.node()] hgfilelogs = p1.manifest().copy() addedp4filelogs = [] Index: hgext3rd/p4fastimport/util.py =================================================================== --- hgext3rd/p4fastimport/util.py +++ hgext3rd/p4fastimport/util.py @@ -35,14 +35,20 @@ r[int(changelist)] = flag.encode('ascii') return r -def lastcl(node): +def getcl(node): if node: assert node.extra().get('p4changelist') or \ node.extra().get('p4fullimportbasechangelist') if node.extra().get('p4changelist'): - return int(node.extra()['p4changelist']) + 1 + return int(node.extra()['p4changelist']) else: - return int(node.extra()['p4fullimportbasechangelist']) + 1 + return int(node.extra()['p4fullimportbasechangelist']) + return None + +def lastcl(node): + clnum = getcl(node) + if clnum: + return clnum + 1 return None def runworker(ui, fn, wargs, items): Index: tests/test-p4fastimport-blobcommit-lfs.t =================================================================== --- tests/test-p4fastimport-blobcommit-lfs.t +++ tests/test-p4fastimport-blobcommit-lfs.t @@ -11,6 +11,12 @@ > threshold=10 > EOF + $ p4 client -o hg-p4-import-narrow | sed '/^View:/,$ d' >p4client + $ echo "View:" >>p4client + $ echo " //depot/Main/... //hg-p4-import-narrow/Main/..." >>p4client + $ p4 client -i Main/a @@ -41,7 +47,7 @@ $ cd $hgwd $ hg init --config 'format.usefncache=False' - $ hg p4fastimport --debug -P $P4ROOT hg-p4-import + $ hg p4fastimport --debug -P $P4ROOT hg-p4-import-narrow loading changelist numbers. 2 changelists to import. loading list of files. @@ -63,49 +69,54 @@ writing lfs metadata to sqlite updating the branch cache 2 revision(s), 2 file(s) imported. + $ cd $p4wd - $ echo thisisanotherlargefile > Main/anotherlargefile - $ p4 add Main/anotherlargefile - //depot/Main/anotherlargefile#1 - opened for add + $ mkdir Outside + $ echo thisisanotherlargefile > Outside/anotherlargefile + $ p4 add Outside/anotherlargefile + //depot/Outside/anotherlargefile#1 - opened for add $ p4 submit -d third Submitting change 3. Locking 1 files ... - add //depot/Main/anotherlargefile#1 + add //depot/Outside/anotherlargefile#1 Change 3 submitted. + $ cd $hgwd - $ hg p4syncimport --debug -P $P4ROOT hg-p4-import + $ hg p4syncimport --debug -P $P4ROOT hg-p4-import-narrow hg-p4-import incremental import from changelist: 3, node: * (glob) - Latest change list number 3 + 2 (current client) 3 (requested client) 2 (latest imported) + latest change list number 3 running a sync import. - writing filelog: fc4d9d827df8, p1 a80d06849b33, linkrev 2, 4 bytes, src: *, path: Main/a (glob) - writing filelog: cf38a89d2b54, p1 000000000000, linkrev 2, 23 bytes, src: *, path: Main/anotherlargefile (glob) - largefile: Main/anotherlargefile, oid: 9703972eff7a4df07317eda436ab7ef827ed16ea28c62abdcd7de269745c610c - writing filelog: fa4df9fc788c, p1 9f14f96519e1, linkrev 2, 88 bytes, src: *, path: Main/largefile (glob) - largefile: Main/largefile, oid: b0d5c1968efbabbff9d94160f284cd7b52686ca3c46cfffdd351de07384fce9c - changelist 3: writing manifest. node: a6a6dbeefd0a p1: c14352bb3510 p2: 000000000000 linkrev: 2 + writing filelog: cf38a89d2b54, p1 000000000000, linkrev 2, 23 bytes, src: *, path: Outside/anotherlargefile (glob) + largefile: Outside/anotherlargefile, oid: 9703972eff7a4df07317eda436ab7ef827ed16ea28c62abdcd7de269745c610c + changelist 3: writing manifest. node: ff600511f8ae p1: c14352bb3510 p2: 000000000000 linkrev: 2 changelist 3: writing changelog: p4fastimport synchronizing client view writing lfs metadata to sqlite updating the branch cache - 1 revision, 3 file(s) imported. + 1 revision, 1 file(s) imported. + $ hg manifest -r tip + Main/a + Main/largefile + Outside/anotherlargefile Verify (waiting for https://patchwork.mercurial-scm.org/patch/20582/) + $ cd $hgwd $ hg --debug verify --config verify.skipflags=8192 repository uses revlog format 1 checking changesets checking manifests crosschecking files in changesets and manifests checking files - 3 files, 3 changesets, 7 total revisions + 3 files, 3 changesets, 5 total revisions $ test -d .hg/store/lfs/objects [1] $ sqlite3 lfs.sql "SELECT * FROM p4_lfs_map" 1|1|*|37a7b43abd9e105a0e6b22088b140735a02f288767fe7a6f4f436cb46b064ca9|//depot/Main/largefile (glob) 2|2|*|b0d5c1968efbabbff9d94160f284cd7b52686ca3c46cfffdd351de07384fce9c|//depot/Main/largefile (glob) - 3|3|*|9703972eff7a4df07317eda436ab7ef827ed16ea28c62abdcd7de269745c610c|//depot/Main/anotherlargefile (glob) - 4|3|*|b0d5c1968efbabbff9d94160f284cd7b52686ca3c46cfffdd351de07384fce9c|//depot/Main/largefile (glob) + 3|3|*|9703972eff7a4df07317eda436ab7ef827ed16ea28c62abdcd7de269745c610c|//depot/Outside/anotherlargefile (glob) End Test Index: tests/test-p4fastimport-blobcommit.t =================================================================== --- tests/test-p4fastimport-blobcommit.t +++ tests/test-p4fastimport-blobcommit.t @@ -2,34 +2,60 @@ $ . $TESTDIR/p4setup.sh + $ p4 client -o hg-p4-import-narrow | sed '/^View:/,$ d' >p4client + $ echo "View:" >>p4client + $ echo " //depot/Main/Narrow/... //hg-p4-import-narrow/Main/Narrow/..." >>p4client + $ p4 client -i Main/a - $ echo b > Main/b - $ p4 add Main/a Main/b - //depot/Main/a#1 - opened for add - //depot/Main/b#1 - opened for add + $ mkdir Main/Narrow + $ echo a > Main/Narrow/a + $ echo b > Main/Narrow/b + $ p4 add Main/Narrow/a Main/Narrow/b + //depot/Main/Narrow/a#1 - opened for add + //depot/Main/Narrow/b#1 - opened for add $ p4 submit -d initial Submitting change 1. Locking 2 files ... - add //depot/Main/a#1 - add //depot/Main/b#1 + add //depot/Main/Narrow/a#1 + add //depot/Main/Narrow/b#1 Change 1 submitted. - $ p4 edit Main/a - //depot/Main/a#1 - opened for edit - $ echo a >> Main/a + $ p4 edit Main/Narrow/a + //depot/Main/Narrow/a#1 - opened for edit + $ echo a >> Main/Narrow/a $ p4 submit -d second Submitting change 2. Locking 1 files ... - edit //depot/Main/a#2 + edit //depot/Main/Narrow/a#2 Change 2 submitted. + $ mkdir Main/Outside + $ echo a >> Main/Outside/a + $ p4 add Main/Outside/a + //depot/Main/Outside/a#1 - opened for add + $ p4 submit -d third + Submitting change 3. + Locking 1 files ... + add //depot/Main/Outside/a#1 + Change 3 submitted. + + $ p4 edit Main/Outside/a + //depot/Main/Outside/a#1 - opened for edit + $ echo a >> Main/Outside/a + $ p4 submit -d fourth + Submitting change 4. + Locking 1 files ... + edit //depot/Main/Outside/a#2 + Change 4 submitted. + Fast Import $ cd $hgwd $ hg init --config 'format.usefncache=False' - $ hg p4fastimport --bookmark master --debug -P $P4ROOT hg-p4-import + $ hg p4fastimport --bookmark master --debug -P $P4ROOT hg-p4-import-narrow loading changelist numbers. 2 changelists to import. loading list of files. @@ -37,58 +63,35 @@ reading filelog * (glob) reading filelog * (glob) importing repository. - writing filelog: b789fdd96dc2, p1 000000000000, linkrev 0, 2 bytes, src: *, path: Main/a (glob) - writing filelog: a80d06849b33, p1 b789fdd96dc2, linkrev 1, 4 bytes, src: *, path: Main/a (glob) - writing filelog: 1e88685f5dde, p1 000000000000, linkrev 0, 2 bytes, src: *, path: Main/b (glob) - changelist 1: writing manifest. node: dbcf87f9f16c p1: 000000000000 p2: 000000000000 linkrev: 0 + writing filelog: b789fdd96dc2, p1 000000000000, linkrev 0, 2 bytes, src: *, path: Main/Narrow/a (glob) + writing filelog: a80d06849b33, p1 b789fdd96dc2, linkrev 1, 4 bytes, src: *, path: Main/Narrow/a (glob) + writing filelog: 1e88685f5dde, p1 000000000000, linkrev 0, 2 bytes, src: *, path: Main/Narrow/b (glob) + changelist 1: writing manifest. node: f32ae4efccd8 p1: 000000000000 p2: 000000000000 linkrev: 0 changelist 1: writing changelog: initial - changelist 2: writing manifest. node: 5c8695bebd8f p1: dbcf87f9f16c p2: 000000000000 linkrev: 1 + changelist 2: writing manifest. node: 11c5dab8abaf p1: f32ae4efccd8 p2: 000000000000 linkrev: 1 changelist 2: writing changelog: second writing bookmark updating the branch cache 2 revision(s), 2 file(s) imported. - $ cd $p4wd - $ p4 edit Main/b - //depot/Main/b#1 - opened for edit - $ echo b >> Main/b - $ echo c > Main/c - $ mkdir Main/d - $ echo e > Main/d/e - $ mkdir Main/d/f - $ echo g > Main/d/f/g - $ p4 add Main/c Main/d/e Main/d/f/g - //depot/Main/c#1 - opened for add - //depot/Main/d/e#1 - opened for add - //depot/Main/d/f/g#1 - opened for add - $ p4 delete Main/a - //depot/Main/a#2 - opened for delete - $ p4 submit -d third - Submitting change 3. - Locking 5 files ... - delete //depot/Main/a#3 - edit //depot/Main/b#2 - add //depot/Main/c#1 - add //depot/Main/d/e#1 - add //depot/Main/d/f/g#1 - Change 3 submitted. Sync Import - $ cd $hgwd - $ cd $hgwd - $ hg p4syncimport --bookmark master --debug -P $P4ROOT hg-p4-import + $ hg p4syncimport --bookmark master --debug -P $P4ROOT hg-p4-import-narrow hg-p4-import incremental import from changelist: 3, node: * (glob) - Latest change list number 3 + 2 (current client) 4 (requested client) 2 (latest imported) + latest change list number 4 running a sync import. - writing filelog: 861f64b39056, p1 1e88685f5dde, linkrev 2, 4 bytes, src: *, path: Main/b (glob) - writing filelog: 149da44f2a4e, p1 000000000000, linkrev 2, 2 bytes, src: *, path: Main/c (glob) - writing filelog: 6b67ccefd5ce, p1 000000000000, linkrev 2, 2 bytes, src: *, path: Main/d/e (glob) - writing filelog: 0973eb1b2ecc, p1 000000000000, linkrev 2, 2 bytes, src: *, path: Main/d/f/g (glob) - changelist 3: writing manifest. node: f0ca72fbd536 p1: 5c8695bebd8f p2: 000000000000 linkrev: 2 - changelist 3: writing changelog: p4fastimport synchronizing client view + writing filelog: b8a08782de62, p1 000000000000, linkrev 2, 4 bytes, src: *, path: Main/Outside/a (glob) + changelist 4: writing manifest. node: * p1: 11c5dab8abaf p2: 000000000000 linkrev: 2 (glob) + changelist 4: writing changelog: p4fastimport synchronizing client view writing bookmark updating the branch cache - 1 revision, 4 file(s) imported. + 1 revision, 1 file(s) imported. + + $ hg manifest -r tip + Main/Narrow/a + Main/Narrow/b + Main/Outside/a Verify @@ -97,54 +100,55 @@ checking manifests crosschecking files in changesets and manifests checking files - 5 files, 3 changesets, 7 total revisions + 3 files, 3 changesets, 4 total revisions $ hg update master - 4 files updated, 0 files merged, 0 files removed, 0 files unresolved + 3 files updated, 0 files merged, 0 files removed, 0 files unresolved (activating bookmark master) -Sync Import without New Changes +Fast Import after Sync Import + + $ hg p4fastimport --bookmark master --debug -P $P4ROOT hg-p4-import + incremental import from changelist: 5, node: * (glob) + loading changelist numbers. + 0 changelists to import. + +Syncimport must abort if there are newer commits - $ hg p4syncimport --bookmark master --debug -P $P4ROOT hg-p4-import - incremental import from changelist: 4, node: * (glob) - Latest change list number 3 + $ cd $p4wd + $ p4 edit Main/Outside/a + //depot/Main/Outside/a#2 - opened for edit + $ echo a >> Main/Outside/a + $ p4 submit -d fifth + Submitting change 5. + Locking 1 files ... + edit //depot/Main/Outside/a#3 + Change 5 submitted. + + $ cd $hgwd + $ hg p4syncimport --bookmark master --debug -P $P4ROOT hg-p4-import-narrow hg-p4-import + incremental import from changelist: 5, node: * (glob) + 2 (current client) 5 (requested client) 4 (latest imported) + abort: repository must contain most recent changes + [255] + +Remove stuff + + $ hg p4fastimport --bookmark master -P $P4ROOT hg-p4-import + $ hg p4syncimport --bookmark master --debug -P $P4ROOT hg-p4-import hg-p4-import-narrow + incremental import from changelist: 6, node: * (glob) + 5 (current client) 2 (requested client) 5 (latest imported) + latest change list number 2 running a sync import. - changelist 3: writing manifest. node: 2037a8409eae p1: f0ca72fbd536 p2: 000000000000 linkrev: 3 - changelist 3: writing changelog: p4fastimport synchronizing client view + changelist 2: writing manifest. node: 38e379ab01af p1: e432a49b940b p2: 000000000000 linkrev: 4 + changelist 2: writing changelog: p4fastimport synchronizing client view writing bookmark updating the branch cache 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 - - $ hg p4fastimport --bookmark master --debug -P $P4ROOT hg-p4-import - incremental import from changelist: 4, node: * (glob) - loading changelist numbers. - 0 changelists to import. - -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 + $ hg manifest -r tip + Main/Narrow/a + Main/Narrow/b End Test stopping the p4 server