8

I would like to know if I can map a file or directory to multiple local copies with perforce.

I know that the P4V does allow me to do that but I encountered very weird behavior from the client and I suspect that this doesn't work.

I do not plan to modify any these files, I need this in order to recreate the same directory structure needed to build my own source tree (I do not want to create a huge branch if I know that I have to modify only few files and also I do not want to create additional workspaces because switching from them takes too much time).

sorin
  • 161,544
  • 178
  • 535
  • 806

5 Answers5

5

You aren't allowed to do that because it leads to Bad Things. You can only map a depot file to one local location and vise versa. You can map two different depot folders to the same local folder, but you have to do it in a way that the files in the local folder will go to only one depot location (well, it will ignore the early mappings that conflict).

Branches can't be "big" because Perforce will make shadow copies until you actually make modifications. In general, you should branch the whole tree. Then you can have a workspace per branch (preferable), or one workspace that maps everything (still doable).

JasonMArcher
  • 14,195
  • 22
  • 56
  • 52
  • Probably Perforce team didn't seriously considered huge repositories with >500.000 files and >30GB. – sorin Jun 28 '11 at 08:26
  • 2
    They have considered that. And there are multiple problems you would run into. If a depot file is in two different local locations, and you sync one of them, then Perforce now thinks they are both synced. If you add a file, and the client mapping shows two possible depot locations, where should Perforce put the file? – JasonMArcher Jun 28 '11 at 16:30
  • It seems that Perforce people are not so used to the concept of symlink and hardlink ;) – sorin Nov 06 '12 at 08:02
4

(sorry - just saw that you don't want to switch workspaces...can you clarify why you think that takes too much time? You can, in p4v, set up "favorite connections" under the connections menu that makes switching a snap. I suppose that hotkeys might make it faster. You also have the option of having mutliple p4v instances open).

Can you simply create a new workspace to do the mapping for you? If you don't intent to modify the files, seems like the easiest way to go. Just create a new workspace and then apply whatever changes you need inside of the workspace mapping. An example:

//depot/src/... //my-test-workspace/src_from_depot/...
//depot/doc/... //my-test-workspace/doc_from_depot/...

That will put the src and doc folders in a src_from_depot and doc_from_depot folder in our workspace root. I'd just put the workspace root somewhere different than you normally work - then you will have copy isolated from where you normally work with a directory structure that has changed to suit your needs.

Stewbob
  • 16,759
  • 9
  • 63
  • 107
Mark
  • 10,022
  • 2
  • 38
  • 41
2

Preforce supports it now.

Map a single depot path to multiple locations in a workspace.

https://www.perforce.com/perforce/doc.current/manuals/p4guide/Content/P4Guide/configuration.workspace_view.one-to-many.html?TocPath=Configure%20clients%7CConfigure%20workspace%20views%7C_____8

To enable the one-to-many mapping feature, prepend & to the mapping line for each additional client location you want to map to:

View:

//Acme/images/logo.png  //bruno_ws/products/images/logo.png
&//Acme/images/logo.png  //bruno_ws/documentation/images/logo.png
&//Acme/images/logo.png  //bruno_ws/support/images/logo.png

When you sync the client, the depot file maps to all three locations.

Important All mapping lines prepended with & are read-only, so in the example above //bruno_ws/documentation and //bruno_ws/support are read only.

nabla
  • 35
  • 5
  • If perforce still in business? Nobody told them to close the lights? – sorin Nov 09 '18 at 17:41
  • 1
    This is a borderline [link-only answer](//meta.stackexchange.com/q/8231). You should expand your answer to include as much information here, and use the link only for reference. – Blue Nov 09 '18 at 19:46
2

It sounds like the real problem may be the time it takes to switch workspaces. If that was fast, then you could maintain separate workspaces per branch.

In the next release, it will be easier to do in-place branch switching. In other words, you can maintain one workspace, and switch it from branch to branch as you work. The p4 sync command adds a new option to only update the files in the workspace that actually differ. So even if your branches are huge (> 500k files, > 30GB data), if only 10 files differ between two branches, moving your workspace from one branch to the other will only update those 10 files. That should be a big time saver.

I'm not sure if this will help or not, but I thought it was worth mentioning.

randy-wandisco
  • 3,649
  • 16
  • 11
1

I have encountered this problem as well. I have files/directories that are common to multiple branches. The common files/directories need to be present in a certain structure in each branch for compilation.

The solution that worked for me was to place the common files/directories in a location separate of the branches. This maintains the perforce 1:1 mapping requirement.

Then, symbolically link the common file/directories to each branch for compilation purposes.

highvelcty
  • 131
  • 1
  • 4