#!/usr/bin/perl -w =head1 NAME move_notify_trigger.pl =head1 SYNOPSIS SHOULD CHANGE ------------- *You need to change the path to your perl interpreter *You need to change the path to your sendmail command *You have to change the path to this script according to where you have placed it - /usr/bin/move_notify_trigger.pl *This is how it should be installed in the triggers table by running "p4 triggers" move_notify_trigger change-commit //depot/... "/usr/bin/move_notify_trigger.pl %change% %client% %user% %serverport%" CAN CHANGE ---------- *You can change the name of the trigger "move_notify_trigger" to something you like. *If you have multiple depots or if you want this trigger only on specific filespec, please change //depot/... accordingly. DON'T CHANGE ------------ *Don't change "change-commit" *Don't change the name of arguments to /usr/bin/move_notify_trigger.pl *DOn't change the order of arguments to /usr/bin/move_notify_trigger.pl =head1 DESCRIPTION This trigger is an effort to flag early in the process that the file got moved to all users having that file opened for their work. Users can take appropriate corrective action once they know that the file got moved/renamed thus saving time and effort and complexity of redoing the fix at later stage with lot more changes than now. TODO: Tell users in which client it is open Contact: thanvk@gmail.com =head1 SEE ALSO p4 help move p4 help fstat p4 help filelog p4 help opened (read about -a option) =cut my $change_number = shift; my $client_name = shift; my $user = shift; my $port = shift; my $file; my $moved = 0; my %moved_list; my $opened = 0; #use the appropriate path for sendmail command my $send_mail = "/usr/lib/sendmail11"; #Get the metadata for submitted files for change $change_number my @p4_output = `p4 -p $port -c $client_name fstat @=$change_number`; foreach my $line (@p4_output) { #Based on the assumption that the output order is same $line =~ s/^\.\.\. //; if ( $line =~ /^depotFile (\S+)/ ) { #Get the file for process $file = $1; $moved = 0; } elsif( $line =~ /^headAction move\/add/ ) { #If the file got moved, get the data from where it got moved. #We need to get this date using filelog as source file don't #say to where it got moved my @filelog_output = `p4 -p $port -c $client_name filelog -m1 $file\@$change_number`; if( $filelog_output[2] =~ /... ... moved from (.*?)#\d/ ) { $moved_list{$1}{moved} = $file; } } elsif( $line =~ /^headAction move\/delete/ ) { #Catch the source file that got moved $moved = 1; } elsif( ($moved) && ($line =~ /^... otherOpen([0-9])+ (.*)@.*/ )) { #If this is the source moved file, collect list of users having #this file open somewhere $moved_list{$file}{$1} = $2; $opened = 1; } } #If anybody has moved file opened somewhere if ( $opened ) { my $user_list; foreach my $file ( keys %moved_list ) { my $i = 0; while( defined ( $moved_list{$file}{$i} ) ) { $user_list .= $moved_list{$file}{$i}; $file_list .= "$moved_list{$file}{$i} - $file moved/renamed"; $file_list .= " to $moved_list{$file}{moved}\n"; $i++; } } my $to = "$user,$user,$user"; my $subject = "You have file(s) opened that are moved/renamed by "; $subject .= "$change_number by $user"; my $email_body = "Below listed user(s) have file(s) opened that got "; $email_body .= "moved/renamed by $change_number by $user\n"; $email_body .= "==========================================================="; $email_body .= "=============================\n\n"; $email_body .= $file_list; open(BODY, "|$send_mail $to") or die("sendmail failed $!"); print BODY <