Mapping Multiple Directories

Info & Tags

Article #:
55
Created:
04/25/07
Modified:
05/16/08

Links

PROBLEM

How do I map two depot directories to the same workspace directory?


SOLUTION

Normally, if your client view maps more than one depot directory to the same directory in your workspace, only the last mapping takes effect. For example, consider this mapping:
//depot/main/util/... //freds-client/util/...
//depot/fred/util/... //freds-client/util/...
The first line is overridden by the second. Using p4 sync with this mapping only syncs files from //depot/fred/util. Furthermore, if your view previously contained only the first line, and then you synced files with that one line view, syncing with this new view removes the //depot/main/util files.

As of server release 2004.2, lower lines that begin with a "+" ("overlay mappings") do not completely override earlier mappings in the previous fashion:

//depot/main/util/... //freds-client/util/...
+//depot/fred/util/... //freds-client/util/...
Instead, overlay mappings override mappings on a file-by-file basis. For example, if any given file exists in //depot/fred/util, then it will be mapped to the corresponding location in //freds-client/util. However, if a file exists in //depot/main/util but not in //depot/fred/util, then that file will be mapped to //freds-client/util instead.


Mapping Multiple Directories, v. 2004.1 and Earlier

If you are using a server that predates the existence of overlay mappings, consider the following alternative approaches to mapping two depot directories to a single workspace directory:
  • Explicitly list every depot file in your mapping. For example:
    //depot/main/util/try.sh        //freds-client/util/try.sh
    //depot/main/util/convert.py //freds-client/util/convert.py
    //depot/fred/util/limitfiles.py //freds-client/util/limitfiles.py
    //depot/fred/util/smashum.sh //freds-client/util/smashum.sh
    This approach works because no lines are overridden by subsequent mappings. However, you cannot add new files to either //depot/main/util or //depot/fred/util with this client view.

  • Provide a general mapping for files in one directory and explicit mappings for files in the other directory:
    //depot/fred/util/...           //freds-client/util/...
    //depot/main/util/try.sh //freds-client/util/try.sh
    //depot/main/util/convert.py //freds-client/util/convert.py
    In this view, try.sh and convert.py map to //depot/main/util, and files of the same name in //depot/fred/util are not mapped. However, all other //depot/fred/util files are accessible to your client, and you can add new files from this workspace directory -- they will be stored in //depot/fred/util.

  • Use "+" mappings to prevent mappings from overriding each other. Warning: prior to 2004.2, this feature was "undocumented" and technically unsupported by Perforce, because it could lead to problematic behavior if used improperly. If you are using a 2003.2 or earlier server, proceed with caution. A mapping line beginning with "+" does not obscure previous mappings, making it possible to directly map two depot directories to one client directory. For example:
    //depot/main/util/... //freds-client/util/...
    +//depot/fred/util/... //freds-client/util/...
    In this view, all files in //depot/main/util and //depot/fred/util are mapped into the single //freds-client/util client directory. Note that problematic behavior occurs (in 2003.2 and earlier servers) if these directories contain identical files. For example, if two files called //depot/main/util/try.sh and //depot/fred/util/try.sh exist, they will take turns overwriting each other in the client workspace each time a p4 sync is executed. Any files added from //freds-client/util will go to the later (higher precedence) mapping in the view -- in this example, //depot/fred/util.

    To view pre-2004.2 documentation on "+" mappings, use the p4 help undoc command.