Saturday, September 01, 2007

Perforce: Changelists resulting from an integration

Perforce has a comprehensive mechanism to track branches and merges (integrations). But there's no direct way to find out the changelists resulting from the integration of a particular changelist.

Given a changelist, P4 doesn't have a direct command that will tell you the changelist(s) resulting from 'outward' integrations. But this can be achieved through a combination of few P4 commands. The rest of this post explains that.


Steps

Step 1
Find out the files affected by the source changelist. One way is to just describe the changelist from the UI and find out the files. The better way is to use the command p4 fstat -e <changelist> <file spec>. If you are writing a script to do this then you need to use the second option. here is an example of the second option,



p4 fstat -e 12345 //depot/...

... depotFile //depot/current/code/Example.java
... clientFile D:\current\code\Example.java
... isMapped
... headAction edit
... headType text
... headTime 869010061
... headRev 10
... headChange 12345



Step 2

For each of the files found from the above step, find out the relevant outward integration record. The command p4 integrated <file spec> can be used for this. Here's an example:




p4 integrated //depot/current/code/Example.java

//depot/current/code/Example.java#6 - branch into //depot/release1/code/Example.java#1

//depot/current/code/Example.java#8 - merge from //depot/current/code/Example.java#2

//depot/current/code/Example.java#10 - copy into //depot/current/code/Example.java#3



Find out the line(s) corresponding to the version found out in step 1. From this you will be able to find out the target file and its version. The final step is to find out the changelist through which this version was submitted

Step 3
Now we know the target file and it's version. Now find out the changelist through which this file was submitted using the command p4 fstat <file#version>. You need to note the value of the field "... headChange".

Perl script
I'm in the process of writing a Perl script to do the above. Will post it here as soon as it is available.

No comments: