ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • Perforce Reverting Another User's Files
    프로그래밍/프로그래밍 관련 2013. 4. 15. 22:43


    There are two ways to revert files opened in a Perforce client workspace for a user other than yourself. The first method can be accomplished with an account with either Perforce admin or super privileges, while the second method can only be performed by a super user account.


    Reverting files by deleting the client workspace


    As a Perforce admin or super user, the simplest solution is to delete the client workspace containing the opened files. For example, if the p4 opened command displays:


    //depot/main/www/training/index.html#8 

    - edit default change (txt) by bruno@bruno_workspace

    Then the "bruno_workspace" client workspace can be deleted with:


    p4 client -d -f bruno_workspace

    Deleting a client workspace reverts all files opened by that client and removes the client's "have" list. However, deleting a client workspace does not remove files stored in the client workspace. To clean up the deleted workspace file system, you must delete the files on the machine containing the workspace.


    Note: Client workspaces containing shelved files cannot be deleted until the shelved files are deleted:


    $ p4 client -d -f bruno_workspace

    Client 'bruno_workspace' has files shelved; use 'shelve -df' to remove them, and then try again.

    To delete the shelved files, locate the changelist containing the files and use the p4 shelve command to delete them. For example:


    $ p4 changes -u bruno -s shelved

    Change 1234 on 2011/01/20 by bruno@bruno_workspace *pending* 'Shelved change '

    $ p4 shelve -df -c 1234

    Shelve 1234 deleted

    Reverting all files for a workspace by impersonating a user


    As a super user, you might want to revert a file without deleting the client workspace. In that case, you can impersonate the user that owns the client workspace and then run the p4 revert command with the "-k" flag to prevent updating the local workspace files (which will likely be on another host).


    For example:


    p4 login user

    p4 -u user -c client -H host revert -k "//depot/dir/file"

    //depot/dir/file#1 - was edit, cleared

    Where file is the file you want to revert, user is the user who has the file open, client is the client workspace where the file is opened, and host is the host name associated with that client workspace. If you do not know the hostname, run the above p4 revert command without -H host, an error message will state the hostname. Then run the command with -H host with the reported hostname.


    Reverting selected files from a workspace by impersonating a user


    As a super user, if you have many files to revert but you do not want to revert all files, place the output of "p4 opened -a" into a file filtered by the client in question.


    In Windows, you would run


    p4 login user

    p4 opened -a | findstr @client > opened.bat

    Edit the "opened.txt" file in your favorite editor and use search-and-replace to change each line to run the proper command.  You may have to surround the file name with quotes.


    p4 -u user -c client -H host revert -k "//depot/dir/file1"

    p4 -u user -c client -H host revert -k "//depot/dir/file2"

    p4 -u user -c client -H host revert -k "//depot/dir/file3"

    Note: This will be much easier in an editor that supports regular expressions to perform the find and replace. For example, this regular expression will capture the depot path, while selecting the entire line for replacement:


    ^(.+)#\d.*$

    Most editors will use "$1" or "\1" as the replacement string, as noted in this example:


    p4 -u user -c client -H host revert -k "$1"

    Consult with your editor's documentation for more information.


    Once the strings have been modified, open a command prompt and run this batch file to revert the files:


    opened.bat 

    'p4 login' and 'p4 revert'


    The 'p4 login user' command gives you a login ticket for the specified user without prompting for a password. Only Perforce user accounts with super privileges can use p4 login in this way. The login ticket allows you to run the revert command with the credentials of the client workspace owner. In order to successfully run the p4 revert command, it is also necessary to specify the client workspace and host field (if any) using the -c and -H global flags. Using the -k flag with the revert command reverts the file without attempting to transfer it back to the client.


    Note: p4 revert -k was added in release 2005.2 of the Perforce Server (change #76292). On earlier server versions, the -k option is not available. In that case, a revert of another user's file(s) only succeeds if the impersonated client workspace Root path can be mapped onto your local system. If the Perforce Server is unable to write the reverted file to your client file system, then the revert fails.


    Resetting user passwords


    Sometimes impersonating the perforce user and client to do a revert can require a Perforce superuser to reset their password. The superuser can simply change the user's password, login as the user, and then revert the files. For example, to reset the password:


    Releases 99.1 and later:


    p4 passwd username

    When prompted, enter a new password for user username.


    Pre-99.1 releases:


    p4 user -f username

    Enter the password in the Password: field of the user specification form.


    Locked client workspace


    In cases where the client workspace is locked, the Perforce admin can use the -f flag option with the p4 client command to modify another user's workspace. For example:


    p4 client -f clientname

    Superusers can use the -f flag to delete or modify locked workspaces owned by other users, and non-superusers can use this flag to delete or modify locked workspaces that they themselves own.

    댓글