Pergunta

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) ?

Foi útil?

Solução

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.)

Outras dicas

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)

Since none of the answers thus far provide the code for finding the source or root changelist of a branch, I thought I'd provide a one-liner to do just that. This approach is based on @Cwan's suggestion, and will print the "parent" changelist from which the branch was created. The FIRST_BRANCH_CL argument needs to be replaced with the branch creation changelist (i.e. the first changelist submitted to the new branch). As a concrete example, replacing FIRST_BRANCH_CL with 130 from the original question, this one-liner would output 123.

p4 describe -s FIRST_BRANCH_CL | perl -lne 'if(/^\.\.\. (.+#[0-9]+) .+$/) {print quotemeta $1}' | xargs p4 filelog -m1 | perl -lne 'if(/^\.\.\. \.\.\. branch from (.+#[0-9]+)/) {print quotemeta $1}' | xargs p4 fstat | perl -lne 'if(/^\.\.\. headChange (\d+)/) {$MaxCL=$1 if($1 > $MaxCL)} END {print $MaxCL}'

Short answer:

Use the Revision Graph in P4V is step back through time and investigate the integration history. Video on the Perforce website.

I have successfully used the revision graph on branches with thousands of files to track when an particular change was integrated into a branch. That is why I recommended it and linked to a training video as most people under-estimate it because they do not know how to use it.

Long answer:

... [Removed]

UPDATE: As the Revision Graph apparently is unfeasible, you can perhaps solve this using a process/policy, i.e., when you perform the integrate, add a note in the description "Branched @ CL 123". We used this approach ourselves when integrating from a trunk to release lines.

If you use the history tab in p4v it will show you all changelists submitted against a branch, so look at this for

//project/1.0/...

once you have found the oldest submitted changelist, then on any one the files in that changelist view the Revision Graph for it, this will show you the branch that the file (and the rest of the files) were integrated from.

I'll see if I can come back with the p4 commands to do the same thing.

Updated Answer: I think this will work. Try this:

p4 interchanges from_branch  to_branch

This will show unintegrated changes from your main branch to your release branch. I believe you can use the top changelist number minus 1 to find your source changelist. interchanges is an undocumented Perforce CLI feature. To find out more, type p4 help interchanges to find out more about this command.

Again, I think this will work. There may be some special cases where it will not, but it's my best guess to a tough and important problem.

"p4 integrated" worked for me. Look for "copy from" in the description

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top