15

Say I created a branch in perforce of our codebase. Here is the branch spec:

//depot/code/main/... //depot/code/branch/...

Then, in the branch, say I move the branched file a.txt -> b.txt using

p4 integrate //depot/code/branch/a.txt //depot/code/branch/b.txt
p4 delete //depot/code/branch/a.txt

Now, let's say some changes are made to a.txt in main which I would like to have integrated into b.txt in the branch

When I try to integrate using the original branch spec, it doesn't reflect the changes made to a.txt in main onto b.txt - is there any way to have the changes made in main show up in the renamed file?

The branch spec is rather large (hundreds of changes) and quite a few files were renamed in the branch, so I'd like to have an automated way to do this. Let me know if I can clarify anything here -- it would help to have a whiteboard ;)

Thanks! Sam

SamBeran
  • 1,944
  • 2
  • 17
  • 24

6 Answers6

13

You can add '-3' switch to use a new engine for integration, which will detect target files that have been previously moved with 'p4 move', and automatically 'retarget' itself to follow those move operations.

p4 integrate -3 //depot/code/main/... //depot/code/branch/...

will integrate your changes in //depot/code/main/a.txt to //depot/code/branch/b.txt.

This is the 'undoc' feature in current 2010.2 release, but will be the default behavior in the upcoming 2011.1.

Alex Che
  • 6,659
  • 4
  • 44
  • 53
3

Perforce 2009.1 has proper renames, which might help with this - probably, and in any case only for future renames. See Perforce 2009.1 release notes, in particular:

#177023 * **
    The new 'p4 move' command allows for better support for
    renaming files.  A file must be already opened for 'edit'
    or 'add' in order to be moved.  Moved files can be synced,
    resolved and diffed against the repository just like files
    opened for 'edit'.  See 'p4 help move' for more info.

You can add the rename into the branch spec. Then at least the integrations will be automatic - even if the branch spec will be even longer and more complicated.

Douglas Leeder
  • 52,368
  • 9
  • 94
  • 137
  • 3
    As far as I understand it, the *only* benefits of p4 move are that you can cleanly move and edit a file in a single atomic changelist, and until you check in that changelist further syncs will propagate changes from the source to the target . *After* you've checked it in, it behaves just the same as a branch, an edit and a delete action except that they are inseparable. It does not help with integrating moves from one branch to another. It is not what is called "first class renames" in other source control systems. – Weeble Feb 16 '10 at 11:58
  • I think you might be right - it looks that way - although, with the meta-data recorded in the database, Perforce might add proper handling in future? Previously it was impossible to differentiate branch from rename. – Douglas Leeder Feb 16 '10 at 12:33
  • Nope, even with a proper `p4 move`, integration won't work as it should. – Laurent Couvidou Nov 19 '12 at 16:58
3

The only way I know of to have Perforce handle this for you is to use the branch spec to map the old file in the original to the new file in the branch. Perhaps that has changed with the new move command in the recent Perforce versions, but not that I've experienced.

Caleb Huitt - cjhuitt
  • 14,785
  • 3
  • 42
  • 49
  • But does this work when you recursively renamed and entire directory? Do I need to make a branch spec for all the files one by one? Seemingly making a branch spec on the directory doesn't work. – Calmarius Feb 09 '15 at 15:44
  • @Calmarius, if you rename the directory, and files in the directory, you need both. If only the directory changed, you could do it with just the directory. If the names changed in a consistent way, you might be able to use wildcards to simplify the spec. – Caleb Huitt - cjhuitt Feb 11 '15 at 19:31
2

You could script the creation of a branch spec for handling moved files using the output of p4 fstat.

Use the following as a starting point:

ROOT_PATH="//depot/books/..."
FIRST_CHANGE=91212

p4 fstat -Os -T headChange -F "headAction=move/* headChange>$FIRST_CHANGE" $ROOT_PATH|grep headChange | sort -u|while read DUMMY1 DUMMY2 change; do p4 describe $change; done|grep "moved from"|sed 's/\.\.\./\t/g; s/\#[0-9]*//g; s/ moved from//g;'

This will find all files in //depot/books/... that were moved in change 91212 or later

For us, the output of this looks like

//depot/books/bar.txt //depot/books/foo.txt

Use it for crafting a branch spec.

1

I don't believe so. Since there is no direct p4 rename, you have to integrate and delete - once you've done that, integrates from another branch no longer go to the right file. At least that's been my experience.

Graeme Perrow
  • 56,086
  • 21
  • 82
  • 121
0

First, I moved the file in target branch using p4 move command. And then, I integrated it.

p4 move //depot/code/**main**/a.txt //depot/code/**main**/b.txt

p4 integrate  //depot/code/**branch**/b.txt //depot/code/**main**/b.txt
tuomastik
  • 4,559
  • 5
  • 36
  • 48