# This script replicates changelists between 2 Perforce servers
require "P4"
require 'getoptlong'
@@g_trace = 0
def trace(*args)
if @@g_trace > 0 then
$stdout.puts args
end
end
def replicate()
begin
p4dest = P4.new
p4dest.parse_forms
p4dest.port = "1666"
p4dest.client = "repl-client-dest"
p4dest.user = "bruno"
p4dest.password = "bruno"
p4dest.exception_level = 1
p4dest.connect
root = "c:\\Data\\Vaccaperna\\Clients\\TTPCom\\Scripts\\root"
view = " //depot/repl/src/... //depot/repl/dest/..."
name = "repl-client-dest"
clients = p4dest.run_clients # <======================= this line causes fetch_client to get corrupted
#~ all_client_names = Hash.new
#~ clients.each {|c| all_client_names[c["client"]] = "1"}
client = p4dest.fetch_client(name)
trace "Client:\n" + client.to_a.join(" ")
#~ if all_client_names.has_key?(name) then
#~ if client["Root"] != root then
#~ raise "Client #{name} already exists - its Root (#{client["Root"]}) is different to config root (#{root})!"
#~ end
#~ else
client["Root"] = root
#~ end
p4dest.save_client(client)
p4dest.disconnect
return 0
rescue P4Exception
# If any errors occur, we'll jump in here. Just log them
# and raise the exception up to the higher level
p4dest.errors.each { |e| $stderr.puts( e ) }
raise
end
end
if __FILE__ == $0
# process the parsed options
opts = GetoptLong.new(
[ "--verbose", "-v", GetoptLong::NO_ARGUMENT ]
)
opts.each do |opt, arg|
if opt == '--verbose' then
@@g_trace = 1
end
end
begin
print "Number of changes replicated: #{replicate()}"
rescue => err
$stderr.puts "Error in script: #{err}\n\n"
$stderr.puts "-----------------------\n"
$stderr.puts "Stacktrace for support:\n"
$stderr.puts $!.backtrace.join("\n")
end
end