sapling/tests/test-p4fastimport-import-client-mapping.t
David Soria Parra 78dcff9f00 p4fastimport: support client view
Summary:
Perforce client support a view. A view maps a server side path to a client side
path, e.g.: the view '//depot/A/B/... //myclient/foo/...' maps every file in
//depot/A/B/ on the server side to a local checkout foo/ inside the root for
checkouts defined for the client 'myclient'.
We are using §p4 where§ to support these mappings. We do the mapping inside the
FileImporter at the moment as this runs nicely in parallel. It's a bit hacky
but get's the job done. We use this mostly to ommit the common prefix
//depot/... and remove branch indicators such as Main.

So in our case a view looks like

  //depot/Software/OculusSDK/PC/Main... //client/Software/OculusSDK/PC/...

resulting in a file

  //depot/Software/OculusSDK/PC/Main/test.txt

being imported as

  Software/OculusSDK/PC/test.xt

Test Plan: rt test-p4*

Reviewers: #sourcecontrol, #idi, ikostia

Reviewed By: ikostia

Subscribers: ikostia, durham, mjpieters

Differential Revision: https://phabricator.intern.facebook.com/D4913483

Signature: t1:4913483:1492702356:b97b691343b8a1d52940445934730b31d411db4c
2017-04-25 15:29:39 +01:00

110 lines
3.1 KiB
Raku

#require p4
$ echo "[extensions]" >> $HGRCPATH
$ echo "p4fastimport= " >> $HGRCPATH
create p4 depot
$ p4wd=`pwd`/p4
$ hgwd=`pwd`/hg
$ P4ROOT=`pwd`/depot; export P4ROOT
$ P4AUDIT=$P4ROOT/audit; export P4AUDIT
$ P4JOURNAL=$P4ROOT/journal; export P4JOURNAL
$ P4LOG=$P4ROOT/log; export P4LOG
$ P4PORT=localhost:$HGPORT; export P4PORT
$ P4DEBUG=1; export P4DEBUG
$ mkdir $hgwd
$ mkdir $p4wd
$ cd $p4wd
start the p4 server
$ [ ! -d $P4ROOT ] && mkdir $P4ROOT
$ p4d -f -J off >$P4ROOT/stdout 2>$P4ROOT/stderr &
$ echo $! >> $DAEMON_PIDS
$ trap "echo stopping the p4 server ; p4 admin stop" EXIT
$ # wait for the server to initialize
$ while ! p4 ; do
> sleep 1
> done >/dev/null 2>/dev/null
create a client spec
$ cd $p4wd
$ P4CLIENT=hg-p4-import; export P4CLIENT
$ DEPOTPATH=//depot/Main/...
$ p4 client -o | sed '/^View:/,$ d' >p4client
$ echo View: >>p4client
$ echo " $DEPOTPATH //$P4CLIENT/..." >>p4client
$ p4 client -i <p4client
Client hg-p4-import saved.
populate the depot
$ mkdir b
$ echo a > a
$ echo c > b/c
$ echo d > d
$ p4 add a b/c d
//depot/Main/a#1 - opened for add
//depot/Main/b/c#1 - opened for add
//depot/Main/d#1 - opened for add
$ p4 submit -d initial
Submitting change 1.
Locking 3 files ...
add //depot/Main/a#1
add //depot/Main/b/c#1
add //depot/Main/d#1
Change 1 submitted.
$ p4 edit a b/c d
//depot/Main/a#1 - opened for edit
//depot/Main/b/c#1 - opened for edit
//depot/Main/d#1 - opened for edit
$ echo a >> a
$ echo c >> b/c
$ echo d >> d
$ p4 submit -d second
Submitting change 2.
Locking 3 files ...
edit //depot/Main/a#2
edit //depot/Main/b/c#2
edit //depot/Main/d#2
Change 2 submitted.
Simple import
$ cd $hgwd
$ hg init --config 'format.usefncache=False'
$ hg p4fastimport --debug -P $P4ROOT hg-p4-import
loading changelist numbers.
2 changelists to import.
loading list of files.
3 files to import.
importing repository.
writing filelog: b789fdd96dc2, p1 000000000000, linkrev 0, 2 bytes, src: *, path: a (glob)
writing filelog: a80d06849b33, p1 b789fdd96dc2, linkrev 1, 4 bytes, src: *, path: a (glob)
writing filelog: 149da44f2a4e, p1 000000000000, linkrev 0, 2 bytes, src: *, path: b/c (glob)
writing filelog: b11e10a88bfa, p1 149da44f2a4e, linkrev 1, 4 bytes, src: *, path: b/c (glob)
writing filelog: a9092a3d84a3, p1 000000000000, linkrev 0, 2 bytes, src: *, path: d (glob)
writing filelog: f83f0637e55e, p1 a9092a3d84a3, linkrev 1, 4 bytes, src: *, path: d (glob)
changelist 1: writing manifest. node: 096669767a87 p1: 000000000000 p2: 000000000000 linkrev: 0
changelist 1: writing changelog: initial
changelist 2: writing manifest. node: 5b4fb7a7d302 p1: 096669767a87 p2: 000000000000 linkrev: 1
changelist 2: writing changelog: second
2 revision(s), 3 file(s) imported.
Verify
$ hg verify
checking changesets
checking manifests
crosschecking files in changesets and manifests
checking files
3 files, 2 changesets, 6 total revisions
$ hg update tip
3 files updated, 0 files merged, 0 files removed, 0 files unresolved
End Test
stopping the p4 server