use P4::test { TESTS => 6, PREREQS => { CATEGORY => 'DISABLED' } }; #`cp /w/24/main/p4-test/server/script/inspect.lua .`; #local ins = require "inspect" write_file 'ws_cloner.53.lua', << 'EOS'; local argparse = require "argparse" local parser = argparse( "workspace cloner", "" ) parser:option( "--from", "" ) parser:option( "--to", "" ) parser:option( "--help", "" ) parser:add_help( false ) local ret, opts = parser:pparse( Helix.Core.Client.GetVar( "argv" ) ) if ret == false then print( "Argparse error", opts ) return false end if #opts[ "from" ] == 0 or #opts[ "to" ] == 0 then print( "Must supply both --from and --to arguments" ) return false end local p4 = P4.P4.new() p4.prog = "example workspace sync/have cloner" p4.version = ".1" p4.api_level = 96 p4.exception_level = 0 p4:connect() if not p4:is_connected() then print( "Error connecting to server" ) return false end function runOne( p4, ... ) p4:disconnect() p4:connect() if not p4:is_connected() then print( "Error connecting to server" ) return nil end local arg = {...} return p4:run( table.unpack( arg ) ) end function wsExists( p4, ws ) local r = runOne( p4, "clients", "-e", ws ) return #r > 0 end if not wsExists( p4, opts[ "from" ] ) or not wsExists( p4, opts[ "to" ] ) then print( "Both the --from and --to workspaces must already exist" ) return false end p4.client = opts[ "from" ]; local fromHave = runOne( p4, "have" ) if #fromHave == 0 then print( "--from workspace has no files synced" ) return false end p4.client = opts[ "to" ]; local toHave = runOne( p4, "have" ) if #toHave > 0 then print( "--to workspace already has files synced" ) return false end local label = "fromHave" local batchSize = 10000 -- Have to chunk this up since table.unpack() has a maximum size limit. for i = 1, #fromHave, batchSize do local files = {} local batchSize1 = batchSize if i + batchSize >= #fromHave then batchSize1 = #fromHave - i end for j = i, i + batchSize1 do local d = fromHave[ j ] files[ j - i + 1 ] = d[ "depotFile" ] .. "#" .. d[ "haveRev" ] end if #files == 0 then break end p4:run( "list", "-l", label, table.unpack( files ) ) end p4.client = opts[ "to" ]; local s = p4:run( "sync", "-q", "-k", "@" .. label ) local numMatch = s[ 1 ][ "totalFileCount" ] == tostring( #fromHave ) if #p4.warnings > 0 or #p4.errors > 0 or not numMatch then print( "Sync did not complete sucessfully" ) return false end p4:disconnect() EOS ; `p4 configure set client.readonly.dir=crd`; like `p4 --script ws_cloner.53.lua --from ws0 --to ws1`, qr /Both the --from and --to workspaces must already exist/; `p4 -c ws0 --field=Type=partitioned client -o | p4 -c ws0 client -i`; #`p4 -c ws0 client -o | p4 -c ws0 client -i`; like `p4 --script ws_cloner.53.lua --from ws0 --to ws1`, qr /Both the --from and --to workspaces must already exist/; `p4 -c ws1 --field=Type=partitioned client -o | p4 -c ws1 client -i`; #`p4 -c ws1 client -o | p4 -c ws1 client -i`; like `p4 --script ws_cloner.53.lua --from ws0 --to ws1`, qr /--from workspace has no files synced/; `p4 -c ws0 have`; `p4 -c ws1 have`; mkdir 'd'; write_file "d/$_" for 0 .. 2; `p4 -c ws0 add d/...`; `p4 -c ws0 submit -d foo`; `p4 -c ws0 edit d/...`; `p4 -c ws0 submit -d foo`; `p4 -c ws0 edit d/...`; `p4 -c ws0 submit -d foo`; `p4 -c ws0 sync d/0#1`; `p4 -c ws0 sync d/1#2`; `p4 -c ws0 have`; `p4 -c ws1 have`; `p4 -c ws1 sync -k ...`; like `p4 --script ws_cloner.53.lua --from ws0 --to ws1`, qr /--to workspace already has files synced/; `p4 -c ws1 sync \@0`; like `p4 -c ws1 have`, qr /File\(s\) not on client/; like `p4 --script ws_cloner.53.lua --from ws0 --to ws1`, qr /^$/; `p4 -c ws1 have`; ################################################################################ exit; `p4 client -d ws1`; `p4 -c ws1 client -o | p4 -c ws1 client -i`; write_file "d/$_" for 3 .. 1000; `p4 -c ws0 -q add -t binary+F d/...`; `p4 -c ws0 -q submit -d foo`; `p4 populate d/... e/$_/...` for 0 .. 10; `p4 populate e/... f/$_/...` for 0 .. 10; `p4 populate f/... g/$_/...` for 0 .. 10; `p4 -c ws0 sync -qk`; like `p4 -c ws0 have | wc -l`, qr /1465464/; like `p4 --script ws_cloner.53.lua --from ws0 --to ws1`, qr /^$/; like `p4 -c ws1 have | wc -l`, qr /1465464/; like `diff <(p4 -c ws0 have) <(p4 -c ws1 have | sed -e s/ws1/ws0/g)`, qr /^$/;
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#1 | 30809 | C. Thomas Tyler |
Code drop with newer versions of Extensions. Thanks to @jason_gibon. #review-30810 @jabson_gibson |