#!/usr/bin/perl # this script takes in a Job or Jobs from Perforce and integrates all the changes # associated with it using a branch spec. This way I only have to write this # script once and you can use it to merge changes from any branch to any other branch, # assuming your workspace can view both branches. # # You also need to pass in a client/workspace name that has both branches in view. # # This script does NOT submit the code, you'll have to do that manually after you verify it. # # Example, note there is a comma and no spaces between the job names: # # perl publish_changelist.pl [job[,job,job]] [workspace] [branchspec] # perl publish_changelist.pl SD-6662,SD-6605 matthewja_generic "publish_main->qa_stream" $fixes = $ARGV[0]; $workspace = $ARGV[1]; $branch_spec = $ARGV[2]; my @master_changelists; # this is used to queue the total list of changelists we are merging # parse out the passed in Jobs into an array, then get all the changelists involved @fixlist = split(/,/, $fixes); # get Jobs list into an array # let's sort the fixlist so it's pretty when we put them in the changelist comment @fixlist = sort(@fixlist); # go through each Job, get the associated changelists, queue said changelists into a master array foreach (@fixlist) { $p4_changelists = `p4 fixes -j $_`; # get output of p4 fixes command @current_changelists = split(/\n/, $p4_changelists); # turn the current list into an array # go through each changelist on the current Job and parse out just the number # then pop it onto a new array of all involved changelists foreach (@current_changelists) { $_ =~ s/^.*change //m; # chop of beginning of line $_ =~ s/ on ....\/..\/.. .*$//m; # chop end of line push(@master_changelists, $_); } } # foreach # let's sort all the changelists we want to merge, we have to do them in numerical order @master_changelists = sort(@master_changelists); # create a new changelist to do the integration with $new_changelist = create_changelist(); # go through the changes list and integrate them using our newly created changelist foreach (@master_changelists) { $integrate_results = `p4 -c $workspace integrate -c $new_changelist -i -d -t -b \"$branch_spec\" //...\@$_,\@$_`; } # foreach # before we auto-resolve the files they should be synced. some files might not need it, so # we parse those out (only things marked for 'integrate' need to (possibly) be synced) # get the pending files $files_to_sync = `p4 -c $workspace opened -c $new_changelist`; # make pending files list into an array @sync_me = split (/\n/, $files_to_sync); # loop through the files in the pending changelist and sync them foreach (@sync_me) { # only things being integrated need to be synced, everything else # will be either an add or delete if ($_ =~ m/ - integrate/) { $_ =~ s/#.*$//; # delete line after pound sign $_ =~ s/#//; # ditch the pound sign $sync_result = `p4 -c $workspace sync $_`; } } # now auto-resolve the files $resolve_results = `p4 resolve -at`; # add the original jobs to the new changelist foreach (@fixlist) { $job_attach_result = `p4 -c $workspace fix -c $new_changelist $_`; } # print out a message print "\n**************************************************\n"; print " Changelist $new_changelist is resolved but not Submitted! \n"; print " Please verify it then check it in!\n"; print "**************************************************\n"; # now you're done!!! # create a changelist and use it so our changes can be isolated sub create_changelist() { # create the new changelist open IN, "| p4 -c $workspace change -i"; print IN "Change: new\n"; print IN "Description:\n"; print IN "\tMerging changelists using branch spec $branch_spec.\n"; print IN "\t\n"; print IN "\tSource Jobs:\n"; print IN "\t\n"; # print out all the jobs we're merging foreach (@fixlist) { print IN "\t\t$_\n"; } print IN "\t\n"; print IN "\tSource changelists:\n"; print IN "\t\n"; # print out all the changelists we're dealing with foreach (@master_changelists) { print IN "\t\t$_\n"; } # foreach close IN; print IN; # now that the changelist is created, we have to find out what number it is. # since we used filehandles to create it, the output result is lost. Good thing # we put a unique description in the changelist that we can search for now, eh? # get the list of pending changes in our workspace $changes = `p4 changes -c $workspace -s pending`; # turn that list into an array @current_changes = split(/\n/, $changes); # go through and find our comment. note that it stops when it finds the first # match. do not keep multiple merges for the same job around. submit them! foreach (@current_changes) { if ($_ =~ m/Merging changelists using branc/) { # found it, let's parse out the change number and return it $_ =~ m/^Change (\d*) /; return $1; } else { print "What the heck? Where did our changelist go? How could you have deleted it in the half second it took to run this script? Merge failed!"; exit; } #if } # foreach } # sub create_changelist
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#1 | 6292 | Matthew Janulewicz |
Adding Perl script to merge changelists associated with job(s) from one branch to another. Script is highly documented. |