7 # ======================================================================
9 # ======================================================================
11 my $perforceBox = "aus-perforce1.soe.sony.com";
13 my $tmpfile = "tmpchangelist.txt";
21 # ======================================================================
23 # ======================================================================
27 print STDERR
"\nUsage:\n";
28 print STDERR
"\t$name <changelist>\n\n";
32 # ======================================================================
34 # ======================================================================
36 usage
() if (@ARGV != 1);
40 # verify perforce user (p4 user -o)
42 # verify password is set
45 open(P4
, "p4 user -o |") || die "p4 user failed\n";
48 $user = $1 if(/^User:\s+(\S+)/);
49 $passwd = 1 if(/^Password:\s+\*+/);
53 die "Password is not set\n" if(!$passwd);
56 # verify changelist's user was the same
58 open(CHANGE
, ">$tmpfile");
59 open(P4
, "p4 change -o $changelist |") || die "error executing p4 change -o";
65 if(/^User:\s+(\S+)/ && $user ne $1)
70 die "Error: Cannot edit another user's changelist\n";
76 # pop up editor and let user make changes to the text (P4EDITOR, EDITOR, VISUAL)
78 $editor = "notepad.exe" if(exists $ENV{WINDIR
});
79 $editor = $ENV{VISUAL
} if(exists $ENV{VISUAL
});
80 $editor = $ENV{EDITOR
} if(exists $ENV{EDITOR
});
81 $editor = $ENV{P4EDITOR
} if(exists $ENV{P4EDITOR
});
83 system("$editor $tmpfile");
85 # verify only the description text has changed
88 open(CHANGE
, "<$tmpfile");
91 my $elem = shift @oldchange;
93 $current = $1 if(/^(\w+):/);
95 if(!defined $elem || $elem ne $_)
99 die "Error: Can only change description of changelist\n";
102 if($current eq "Description")
104 $buffer = "Description:\n";
118 my $tmp = shift @oldchange;
119 if($tmp =~ /^(\w+):/)
128 die "Error: Can only change description of changelist\n" if(@oldchange);
130 # send the data to the daemon
131 socket(PERFORCE
, PF_INET
, SOCK_STREAM
, getprotobyname('tcp')) || die "socket failed\n";
133 my $destination = inet_aton
($perforceBox) || die "inet_aton failed\n";
134 my $paddr = sockaddr_in
($port, $destination);
135 connect(PERFORCE
, $paddr) || die "connect failed\n";
137 # unbuffer the socket
138 my $oldSelect = select(PERFORCE
);
142 # put the socket into binary mode
146 print PERFORCE
pack("N", length "$user $changelist");
147 print PERFORCE
"$user $changelist";
149 print PERFORCE
pack("N", length $buffer);
150 print PERFORCE
$buffer;
152 die "Error getting response from Perforce server\n" if(read(PERFORCE
, $buffer, 1) != 1);
156 print "Successfully updated changelist\n";
160 print "Error updating changelist\n";