Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Perforce: Find source changelist for a branch

Short version:

After branching in P4, how can I find out the "source" changelist of the branch?

Long version:

Let's say I have a main branch of my project at

//project/main/...

The latest changelist submitted here is @123, when I decide to create a branch for release 1.0 in

//project/1.0/...

From P4V, a new changelist is created (say @130), resolved and submitted.

From the CLI, it would look something like this:

p4 integrate -c 123 -o //project/main/... //project/1.0/...
p4 submit

Later, I look at the changelists under //project/1.0, and see the @130 changelist containing a lot of branched files. How can I find out the changelist no. that this was originally branched from (that is, @123) ?

like image 309
Cristian Diaconescu Avatar asked Nov 03 '10 15:11

Cristian Diaconescu


People also ask

What is Perforce default Changelist?

Perforce maintains a default pending changelist in the system metadata for every workspace. When you check out a file, you can add it to the default pending changelist for your workspace or create a new numbered pending changelist for your work.

What is branch mapping in Perforce?

The branch mapping is used by the integration process to create and update branches., which specifies the relationship between two codelines. When you branch, you can use the branch mapping instead of a file mapping. Branch mappings are displayed in the right pane on the Branch Mapping tab.

Are there branches in Perforce?

What Is Perforce Branching? Perforce Streams. All version control systems have branching.

How do you integrate with P4V?

To integrate files, you open them for integration, specifying source and target, then submit the changelist containing the open files. P4V performs three types of integration: Branching, which creates a new codeline or branch. For more information, see Creating Branches.


2 Answers

p4 changes will display a list of submitted changelists, optionally filtered to a specific path.

p4 changes //project/main/...
Change 123 ... 'Very last change.'
Change 122 ... 'Next-to-last change.'
Change 100 ... 'Only two changes to go...'
...

No surprise there, but, as you've found, p4 changes is less helpful when you integrate all those changes in a single change:

p4 changes //project/1.0/...
Change 130 ... 'Integrated everything from main.'

The trick is to use the -i option which includes any changelists integrated into the specified files.

p4 changes -i //project/1.0/...
Change 130 ... 'Integrated everything from main.'
Change 123 ... 'Very last change.'
Change 122 ... 'Next-to-last change.'
Change 100 ... 'Only two changes to go...'
...

To get exactly what you want (123) you'll need to write a script which filters the output from p4 changes -i //project/1.0/... to remove any change listed by p4 changes //project/1.0/... (and then take the most recent remaining change).

(When exploring, I frequently also find the -m max option useful. This limits changes to the 'max' most recent. This helps your output not flow offscreen when there are many changes.)

like image 74
Jon-Eric Avatar answered Oct 04 '22 14:10

Jon-Eric


I don't know of any simple command that performs what you would like to do. If you are willing to script a little bit and the command doesn't have to execute fast you could perhaps try to script something like the following for all branched files:

  1. Find the source file/revision for a target file.

    p4 filelog //project/1.1/foo.bar#1
    //project/1.1/foo.bar
    ... #1 change 6416 branch on 2009/07/10 by foo@bar (text) 'Release 1.1'
    ... ... branch from //project/main/foo.bar#1,#2

  2. Get the change list at which the source file/revision was submitted.

    p4 fstat //project/main/foo.bar#2
    ... depotFile //project/main/foo.bar
    ... headAction edit
    ... headType text
    ... headTime 1201771167
    ... headRev 2
    ... headChange 5353
    ... headModTime 1201770971

  3. Repeat for all files in branch and select the highest change no (headChange above), which should be the latest change submitted to the parent before branching for that specific file. You could get a complete listing of all branched files using e.g. "p4 files //project/1.0/...#1".

(or perhaps take the easy way out and ask Perforce support)

like image 29
rjnilsson Avatar answered Oct 04 '22 13:10

rjnilsson