perforceperforce-client-spec

perforce forbid adding to overlay


Couple of questions on p4 overlay mappings.

If one has an overlay client view:

  //depot/dir1/...  //ws/build/...
  +//depot/dir2/... //ws/build/...
  1. Is it possible to forbid files to be added to //depot/dir2 ?

  2. How does one specify if the target of a p4 add command is //depot/dir1 or //depot/dir2 ?


Solution

  • When an overlay causes multiple depot paths to map one client path, the default for a p4 add (in client syntax) is the last mapping. If you specify a depot path, that path is used:

    C:\Perforce\test\depot>p4 where ...
    //depot/dir1/... //classic/... c:\Perforce\test\depot\...
    +//depot/dir2/... //classic/... c:\Perforce\test\depot\...
    
    C:\Perforce\test\depot>p4 add -n foo
    //depot/dir2/foo#1 - opened for add
    
    C:\Perforce\test\depot>p4 add -n //depot/dir1/foo
    //depot/dir1/foo#1 - opened for add
    

    So just flipping the order of your mapping lines may give you the effect you want (e.g. you can make dir1 the default by specifying it last in the mapping). It will still be possible to add files to dir2 explicitly but it's not likely to happen by accident.

    If you want to specify in the client that dir2 is a read-only path and you can't add files to it, the ChangeView can be used for that (since anything you map in a ChangeView is automatically made read-only):

    C:\Perforce\test\depot>p4 client -o | tail -n3
    ChangeView:
            //depot/dir2/...@now
    
    
    C:\Perforce\test\depot>p4 add -n //depot/dir2/foo
    //classic/foo - can't add file that is restricted by client's ChangeView mapping
    
    C:\Perforce\test\depot>p4 add -n //depot/dir1/foo
    //depot/dir1/foo#1 - opened for add
    

    In this example I'm using @now as the revision for the ChangeView because I don't actually want to restrict the versions; I just want the side-effect of the path being restricted to read-only operations.

    Another way to make a path read-only is to remove write permission via p4 protect; that would be the better solution if you want to make this a global policy for all users.