Sunday, 8 June 2014

Perforce Proxy Server Setup


Perforce Proxy Server Configuration :

System Requirements

* Perforce server: 2002.2 or higher
* Perforce clients: any version, any client program
* OS requirements: sufficient disk space for storing file revisions
 (P4P does not store server metadata)


Starting P4P

To start P4P, you invoke the p4p executable.  For example,
the following command line starts a proxy that communicates
with a central Perforce server located on a host named
'centralserver', listening on port 1666.  Perforce clients
connect to P4P on port 1666 on the machine where the proxy
runs.  P4P file revisions will be stored under a directory
named /local/proxyroot.

        p4p -p 1666 -t centralserver:1666 -r /local/proxyroot

The following command-line flags are supported.

* Proxy-specific options

-c              Do not compress files transmitted from the
               Perforce server to P4P
-d              Run as a daemon (fork first, then run)
-f              Run as single-threaded server
-i              Run for inetd (socket on stdin/stdout)
-q              Suppress startup messages
-s              Run as an NT service (or invoke as p4ps)
-e size Only cache files larger than size bytes
(default $P4PFSIZE or zero)

* General options

-h or -?        Display this message
-L log          File to which messages are logged
               (default $P4LOG, or stderr if $P4LOG is not set)
-p port         Port on which P4P accepts Perforce client requests
               (default $P4PORT or 1666 if $P4PORT is not set)
-r root         Proxy cache directory (default $P4PCACHE or directory
               where p4p is started if $P4PCACHE is not set)
-t port         Port that P4P uses to connect to a server
(default $P4TARGET or perforce:1666 if
$P4PORT is not set)
-v level        Specifies debug mode (see Perforce System
Administrator's guide for details; default
$P4DEBUG or none if $P4DEBUG is not set)
-V              Display the version of the Perforce proxy


Administering P4P

* No backups required

 You do not need to back up the P4P cache directory.
 If necessary, P4P reconstructs it based on Perforce
 server metadata.

* Loading the cache directory to obtain best initial performance

 P4P stores file revisions only when one of its clients
 requests them.  File revisions are not "prefetched." Note
 that the performance gain that is provided by P4P only
 comes into effect after file revisions are cached.  After
 starting P4P, you can load the cache directory by creating
 a client and syncing it to the head revisions, enabling
 other clients that subsequently connect to immediately
 obtain the performance improvements provided by P4P.

* Managing disk space consumption

 P4P saves file revisions in its cache directory.  Note
 that P4P's disk space consumption only increases.  P4P
 does not delete its cache files or otherwise manage its
 consumption of disk space.  To recover disk space, remove
 files under the proxy's root.  It is safe to delete the
 proxy's cache files while the proxy is running.

* Protections

 The p4 protect command can distinguish connections coming
 from a proxy if the string 'proxy-' is prepended to the
 IP addresses of the true client and used in the protections
 table.  For example, 'proxy-*' applies to all connections
 from all proxies and 'proxy-10.0.0.5' identifies a host
 with an IP address of 10.0.0.5 and connecting to p4d
 through a proxy.

* Remote Depots

 The proxy is designed to operate between a p4 client and
 a p4 server (p4d).  It does not work between two p4 servers
 in a remote depot configuration.  Attempting to connect
 to a remote depot via a proxy will result in the proxy
 logging an error about this configuration (i.e. can not
 proxy for remote depots) and an error at the p4 server
 about unable to access remote depot and an error at the
 client.


Perforce Server Configuration and Client Configuration


Server Side Configuration....
=========================================
Step : 1 Download p4d (Binnary) (In Home Directory)

    http://ftp.perforce.com/perforce/r07.3/

     Install The Perforce Server,

     Export The Perforce Root Directory Path,

     export P4ROOT="/home/perforce/perforce_root"    
     
    Start Perforce Server, 

     /home/perforce/perforce_root/p4d -J /home/perforce/perforce_root/journal -L /var/log/p4err -p 1666 &


If you need stop Perforce Server ,

p4 -p 192.168.100.1:1666 -u  PUSER  -P  PPASSWORD -c WORKSPACE admin stop


Client Side Configuration....
====================================

Step : 1 Download p4 (Binnary) (In Home Directory)

http://ftp.perforce.com/perforce/r07.3/


Step : 2 Export the following Variable 


For Linux,
export P4PORT=(Perforce Server IP with Port) 192.168.100.1:1666
export P4USER=(Perforce User)
        export P4PASSWD=(Perforce Password)
export P4CLIENT=Worlspace name (which provided by me)

p4 -p 10.201.3.125:1666 -u cyberoam -P cyb3r2o13 -c build admin stop        Set P4PORT=(Perforce Server IP with Port) 192.168.100.1:1666
Set P4USER=(Perforce User)
        Set P4PASSWD=(Perforce Password)
Set P4CLIENT=Worlspace name (which provided by me)


After run the p4 command,


Perforce Working with Chang-lists :

Perforce Working with Chang-lists :


Open files won't affect the depot until we submit them. And when we submit files to the depot it means we are changing our source code and it generates changelist. What we submit to the depot is not an individual file but the entire pending changelist.

1. How to submit changes

#p4 submit

submit commans is used to apply the changes to the depot. By default, it operates on the default pending changelist
This will open submit spec from, similar to p4 client, but it comes with prefilled list of files in the changelist we just  have to edit the description for the changelist.

2. How could i prevent unchanged files from being submitted

#p4 revert -a

Actually revert command reverts changes made to files those are not changed.
Here, -a flag causes revert only reverts files those are not changed

3. How do I  create seperate changelists.

Changelists are meant to document files changed together as a single unit of work. However, its easy to end up with unrelated files in default pending changelist. If it happens, consider splitting files in to changelists that can be submitted saperately.

#p4 change

change command is used to create seperate changelist. The command brings up spec from just like submit. The form will list all files opened in default changelist. simply fill in a description and save them to move files to new changelist.
Saving form doesn't submit changes instead it generates another change number.

4. How do I know which changes are pending.

#p4 changes -s pending

p4 changes -s pending commands shows all changes those are pending.

#p4 changes -s pending <client name>

Above commands shows changes those are pending for given client

5. How to move files from one changelist to another

once we have more than one pending changelist, we can use reopen command to juggle open files between them

#p4 reopen -c default <filenames>
or
#p4 reopen -c <change no> <filen name>

6. How do i know what's there in pending changelist?

#p4 opened -c <change no>

opened command shows files opened for pending changelist
-c flag takes change no to show up what's in changelist

7. How do I submit pending changelist

#p4 submit -c <change no>

-c flace takes change no to submit

8. How could I delete empty pending change list 

#p4 change -d <change no>

-d flag deletes empy changelist

9. How can I submit subset of opened files.

#p4 submit <file spec>
#p4 submit //depot/Release1-2010-X.2/bbb/...

By supplying file spec to submit command perforce will split default changelist in to two. The first new chagelist, containing the files that mat chwith file spec, is submitted. And rest of other files will remain open.

10. How do I know which files need to be resolved.

#p4 resolve -n

p4 resolve -n command list files required to be resolved


11. How to cancel pending changelist having more than one file

- List out the files in changelist
- Filter out the output of the command
- verify filtered output against files to be reverted
- List out files going to be affected using revert command
- Apply revert command on all those files

#p4 opened -c 16127
#p4 opened -c 16127 | awk -F "#" '{print $1}'
#p4 opened -c 16127 | awk -F "#" '{print $1}' | tr '\n' ' '
#p4 revert -n `p4 opened -c 16127 | awk -F "#" '{print $1}' | tr '\n' ' '`
#p4 revert `p4 opened -c 16127 | awk -F "#" '{print $1}' | tr '\n' ' '`

This will cancel pending changelist

12. Backing out recent changes.

For example, to back out changes 1245.

1. Get the list of files in the changes lists 1245

#p4 files @=1245


2. sync with previous change list files.

#p4 sync @1244

3. Now open files affected by changes list 1245, edited for edit, deleted for add and added for delete

#p4 files @=1245 | sed -n -e "s/#.* - delete - .*//p" | p4 -x- add
#p4 files @=1245 | sed -n -e "s/#.* - edit - .*//p" | p4 -x- edit
#p4 sync
#p4 files @=1245 | sed -n -e "s/#.* - add - .*//p" | p4 -x- delete

4. Now resolve your files with perforce files.

#p4 resolve -ay

5. Submit them

#p4 submit





Perforce Working with Local File (Workspace)

Perforce Working with Local Files 

When depot files are synchronized to the workspace, perforce normally puts read-only files on local disk. To edit files or to make them writable one have to open them. One also have to open files to add or delete from the depot.

Here, open doesn't mean opening file in application, it means file is open for submit.

1. How to open file for edit

#p4 edit test.c

edit command is used for editing file locally.
Opening files for editing makes them writable so we can edit them locally. These changes are local and not visible to other until we submit our open files to the depot.

2. How do I know which files I am working on.

#p4 opened

opened commangs list all files open for edit.

3. How do I know who others are working on file.

#p4 opened -a test.c

-a flag lists opened files in all clinets

4. How do I know which files I have changed

Is helpful to ensure, are opened files really changed before submitting.

#p4 diff -sa

-sa flag lists opened files that are different from the revision in the depot

We can also view the changes content of changed files.

#p4 diff

without -sa flag It will also display changed contents of files.

diff command compares depot revision file and workspace file for changes.

5. How do I add new file to the depot

#p4 add newadd.c

add command is used to add a new file to depot.

file can only be added if they are in current workspace view, if not then first move them to withing current workspace view then run add command.

perforce wildcards won't be working in new files to be added

6. How could i add entire directoy to the depot

perforce don't understands directory. so to add whle directory to the depot find command is used to search for the files in directory and it out put is given to p4 command to add each files.

#find . -type f -print | p4 -x- add -f

By doing this we don't need to do anything, perforce will create diretories it self

7. How to delete file from the depot

#p4 delete test.c

delete command opens file to be deleted, it also them from the workspace and from t he depot when submit command is run.

8. How to create duplicate file/directory or clone existing file/directory
   How to integrate file/directory

integrate command is used to create a clone of existing file/directory

#p4 integrate test.c hi.c
#p4 submit

this create a clone hi.c for test.c and opens up hi.c file (for branching) and just need to submit.

In the same way we can create a clone for directory

#p4 integrate projectA/... projectB/...
#p4 submit

Its's also possible to copy file/directory to other place in workspace and use add command to open them as they are new files. But, in this way it won't inherit file/directory history from their originals

9. How to modify file as I clone it

cloned files are copied in to workspace first, and will appear as a read-only files. To modify them after integration reopend them with reopen command. This makes them writable at lease until we submit it.

#touch case.c
#p4 integrate case.c if.c
#ls -l
#p4 reopen if.c
#ls -l
#p4 submit if.c

10. Ranaming files/directories

Renamig files/directories is just like cloning, the only difference is we have to delete originating file

#p4 integrate hat1.c hat01.c
#p4 delete hat1.c
#p4 submit

Here, we integrated hat1.c to hat01.c and deleted originating hat1.c, this will also keep history.

Same for the directories.

#p4 integrate www/prod/... www/products/...
#p4 delete www/prod/...
#p4 submit

This will rename www/prod to www/products

11. How to replace file contents with other file.

to replace file content of welcome.c with the content of hello.c

#p4 integrate -i hello.c welcome.c
#p4 resolve -at
#p4 submit

-i flag enables integration with files that have no integration history. Normaly, p4 integrate command refuses to integrate changes if there is no prior integration history between the source and target, because it has no way to identifying the base for its merges. So -i flag forces baseless merges and tells p4 resolve just to use first added revision as the base
resolve command merges the open files with other revisions or files.
-at flag performs an automatic resolve that skips the merging instead it automatially accepts their version of file. It overwrites any changes made to the file in the client workspace

12. How to swap file contents.

swapign file content is similar to replacing files contents.

To replace files contents fo first.c and second.c

#p4 integrate -i first.c second.c
#p4 integrate -i second.c first.c
#p4 resolve -at
#p4 submit

13. How to locking files

Once you opened files in perforce for editing,perforce will warn others it they open the same file in their workspace even it won't prevent others from submitting their changes before you submit them.

To prevent others from submitting changes first, opened files must be lock. lock command is used for that.

#p4 lock

14. How to change the file type of existing file

When file is submitted, perforce records it file type accordingly. That is the filetype that stays with it revision to revison an also inherited to the files branched from it

To change file's file type edit command is used

#p4 edit -t +w case.c

-t flag changes the default file type detected by perforce to the given type.

15. How to check what is the file type of file

#p4 filelog case.c

displays filetype of file case.c

file type can also be change by reopen and open command in the same way.

16. How to revert files

To discard changes that made to open file is possible using revert command.

#p4 revert case.c

revert command doen't save backup copies of your changes workspace file. It just overwrites them with the fresh copies from the depot files.


17. It is possible to change local/workspace files without edit/open them.

We are free to change the workspace files to edit them without open/edit command by changing their files permissions. But, we won't be able to submit them to the depot.

18. How do I know which files are modified locally.

#p4 diff -se

diff command is used to view change between workspace and depot.

-se flag lists unopened files that don't match their depot counterparts

To open them for editing and submit changes, command given is

#p4 diff -se | p4 -x- edit

19 How do I know which files are deleted locally.

#p4 diff -sd

-sd flag lists unopened files that are missing from the client/workspace

Perforce with Synchronization ( p4 sync )

Perforce Synchronization : (P4 SYNC Command)

Workspace is now ready and we can start work on perforce. The next step after configuring a workspace and making it the current workspace is to synchronize it.

During synchronization perforce does two things.

1. It copies files from the depot to the workspace/local disk.
2. It makes an internal record of the file revisions you have on disk.

Perforce can sync as often as you like, it's just refreshes only the files that have changed. It naver makes recopy of files that are already present in workspace.


1. How to syncronize the entire workspace

#p4 sync

Without argument sync command synchronizes entire workspace. It copies latest version of depot files to their corresponding locations on your local disk/workspace.

2. How to list unsynchronized files

#p4 sync -n

-n causes sync not to update the client workspace, but to display what would be updated.

Used if you want the preview of files you need to synchronize, or if you just want to know which depot files have been updated since the last time you synchronized.

3. How to synchronize particular module/directory 

#p4 sync //depot/Release2-2010-HA/bbc/...

Normally command sync operates on entrire workspace. But by providing file spec to sync command it will sync only that piece of directory from depot.

4. How to synchronize specific type of files from the depot.

#p4 sync "//.../*.c"

This synchronizes only the *.c files rather than the entire workspace

5. How do i know when did I last synchronize

Perfoce  can't actually tell you when you last ran the sync command, but it can give a clue.

#p4 change -m 1 "#have"
        Change 15273 on 2010/06/18 by applications_rnd@vinod.patel.linux 'BUGID: CLITE-3 554. Some of the '

Here, this commands tells that your workspace was probably last synchronized with depot revision 15273 on 2010/06/18. The #have filespec is a shorthand for all the files in the workspace.

-m parameter to changes command limits output to the single most recent change.

We say probably last synchronized because all changes is really telling us is that 18 Jun 2010 is the date of latest revision of the files in workspace.

6. How do i know what is new in the depot.

changes command can be used that gets an idea of the changes that have occured in the depot since your last synchronized

first get your have version and then again view changes newer then that.

#p4 changes -m 1 "#have"
        Change 15273 on 2010/06/18 by applications_rnd@vinod.patel.linux 'BUGID: CLITE-3 554. Some of the '
#p4 changes "@>15273"

"@15273" is undocumented syntax that means revisions after 15273.

7. How can i get help of undocumented syntax of perforce.

#p4 help undoc

8. How to sync with the older version of the depot.

Normaly, perforce copies the head revision of files to the workspace. To sync with older revisions, we need to supply a revision identifier. For example,

#p4 sync //depot/Release2-2010-HA/...@2010/03/30

Here, 30 March 2010 revision of //depot/Release2-2010-HA directory tree will be copied to the workspace.

9. How to list files those are in workspace

#p4 have //depot/Release2-2010-HA/...

This lists the files perforce thinks that you have with have command.


10. How to detect how many files are missing in workspace

In perforce the list of files in workspace is called have list. The have list is actually inventory of files that have been synchronized, not an invenroty of files actually in workspace because it may include files that have since gone missing, and it doen't include files that come from the depot.

#p4 diff -sd

-sd flage lists unopened files that are missing on client

11. How to replace missing files.

workspace files are under users control and there is nothing to stop him to erasing files perforce put there. Also perforce thinks that you have already those files and you won't be able to replace them with simple sync command.

To force perforce to recopy file it thinks you already have, -f paramater used with sync command

#p4 sync -f //depot/...

This will recopy whole depot to the workspace. Its also possible to only make recopy of files that have been missing by,

#p4 diff -sd | p4 -x- sync -f

-x instructs p4 to read arguments one per line from the named file. If the file is named '-', then standard input as read
-f makes recopy of the file in workspace even though perforce thinks you already have them

12. How to detect files that not come from depot.

#ls --format=single-column | p4 -x- have > /tmp/have.txt 2>/tmp/havenot.txt

The ls command generates list of files in current directory in single column format and p4 with -x- flag gets that file as parameter and checks for its have version

Files those are from depot are redirected to /tmp/have.txt and those not are redirected to /tmp/havenot.txt

Perforce and Workspace

Workspace Operation :


Perforce refers workspace as a client.

A client workspace specification or client spec, tells perforce where in your local filesystem you want your workspace to be rooted. It has a view that defines the areas of the depot you want access to, and maps them to directories beneath the workspace root. Once set up has been done, you can work on files.

Perforce database model has many non-file objects, including workspace, user, user group, depots etc. The interface to these non-file objects is what perforce calls spec forms. Perforce gives a spec form to edit/create any non-file object.


1. How to create or edit client/workspace

#P4 client <client/workspace name>

This command brings up a spec form in editor for the client specified with this command. If no name is given then p4 will use the hostname of that machine. Mapping is very much important in perforce workspace.


2. Setting up current workspace.

P4 programs uses P4CLIENT environment variable to detemine the current client workspace name. If P4CLIENT is not set, the name of your hostname will be used as the current workspace name. Need to just set up P4CLIENT varaible in your environment.

2. How to delete client/workspace from the perforce server.

#p4 client -d <client/workspace name>

-d parameter causes the named client to be deleted

3. How to list all clients/workspaces in perforce server.

#p4 clients
or
#p4 workspaces

This command lists all the clients/workspace on perforce server

Each line represent

Client <client name> <date client created> root <client root> <description of client>

4. How to identify the client/workspace.

#p4 info

This will list all information like client name,host name,client root,client address,server address,server root, server date, server version and license.

5. How to see client spec form without opening up editor.

#p4 client -o <client/workspace>

-o causes the name client/workspace specification to be written to the standard output

What is Perforce (SCM Tool) ?

What is Perforce ?

Perforce is an enterprise version management system in which users connect to a shared file repository. Perforce applications are used to transfer files between the file repository and individual users' workstations.


Perforce is widely used because of its portability and platform independent file syntax that it provides.

Perforce provides its own uniform syntax for refering to workspace and depot contents. This syntax is known as a file specifier or filespec. A filespec can refer to a single file or a collection of files, to a specific revision or a range of revisions, and to depot files or workspace files.

The filespec syntax appies to all operation system, perforce converts filespecs to native file references for local operations.



What is Depot & Workspace ?

"Depots" - where perforce keeps master file content and "workspace" - where users work on the files are hierachical structures of directories and files.

A filespec uses "//" to indicate the root of the hierachy, and "/" as a directory path and file name seperator.

i.e.

//depot/ReleaseX-2014-R1/conf/onel.sh.


We often refer to an entire repository as "the depot", However, there can be multiple depots in perforce repository.

The filespec root idetifies the name of the depot. The filespec "//depot/ReleaseX-2014-R1/conf/onel.sh" refers to a depot named "depot"

Wildcard and File collections .

When filespecs contains wildcards, they define entire collections of files instead of single file.

"*" wildcard matches characters in filenames at a directory level.

i.e

For filespec like,

ProjectA/d*/*.html

can define collection of files

ProjectA/dev/index.html
ProjectA/dev/diag.html
ProjectA/doc/index.html


"..." wildcad matches characters in filenames at or below directory level. A filespect that ends in "/..." is a succinct referece to the complete colletion of files in directory hierarchy.

i.e

For,

ProjectA/... refers to the files in the ProjectA directory

ProjectA/bin/win32/app.exe
ProjectA/bin/win32/app.dll
ProjectA/dev/index.html
ProjectA/dev/main.cpp
ProjectA/doc/app/index.html
ProjectA/doc/app/reference.html
ProjectA/doc/diagnostic.html


Views and Mappings

A filespace is a special case of the perforce construct called view.

Perforce database stores views for variety of uses, including access permission, labels, branching, triggers and chage reviews. The scope of every perforce operation is constrained by the views that affect it.

some of the views involed - filespec view or workspace view



p4 dirs
p4 depots
p4 changes
p4 describe
p4 files
p4 filelog
p4 annotate
p4 print
p4 diff2