Book Image

Learning Perforce SCM

By : Neal Ralph Firth, Robert Cowham
Book Image

Learning Perforce SCM

By: Neal Ralph Firth, Robert Cowham

Overview of this book

<p>Learning Perforce SCM is a pragmatic how-to guide, explaining the key concepts and usage of Perforce. Based on the authors' experiences training thousands of users around the globe, it explains those key concepts in a clear, incremental manner, combining sound theory with the pragmatic application of principles.<br /><br />Learning Perforce SCM provides practical knowledge which will transform you into confident and competent Perforce users in your day-to-day operations.<br /><br />You'll start by learning how to use Perforce to track your day-to-day coding activities. Once a solid foundation is established you'll learn how to apply the data mining features to evaluate current and past activities. Then you'll learn how to configure Perforce so that it adapts to support your specific development needs. All the while you'll be learning how to deal with conflicts and use the tool to communicate with other team members. Finally, you'll learn about using branches and streams to provide seamless support for concurrent development. Along the way, pragmatic hints and tips will help you avoid issues and identify areas for further personal exploration.</p> <p><em>"It's wonderful to see a new book about Perforce, especially one written by Robert Cowham and Neal Firth. No one can teach Perforce better than these seasoned subject matter experts"</em><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp; -&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <em>Laura Wingerd, author of Practical Perforce.</em></p>
Table of Contents (19 chapters)
Learning Perforce SCM
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Basic notes on using commands


Many commands have a singular version (for example, workspace) that provides for create, modify, and delete of an individual element. The plural version of that same command (for example, workspaces) lists all those elements. This makes descriptions of what you're trying to achieve using a command grammatically correct, except of course for the few commands such as sync, fstat, and filelog which aren't actual English words.

Command options

Many commands provide a preview capability. Unlike most systems, Perforce preview output is the same as the output generated for full functionality. This can be very useful for development and debugging. The –n option provides preview for the commands that support it.

Filters are provided by command options and arguments. Using filters can significantly reduce the overhead associated with processing a command.

If you look closely you'll find that P4V uses command options that provide functionality that is unique to the needs of GUIs such as P4V. You don't need to duplicate every command option that you see P4V use.

Tip

If you are not sure which command is the right one, you will get helpful responses (including perhaps from the authors!) if you post a question on the Perforce User Forums (http://forums.perforce.com/). Posts are also mirrored to a mailing list which you can subscribe to (see http://www.perforce.com/community for more options).

Command input and output

There are several different types of command. They all take parameters and options. They can be loosely classified as:

  • Action commands: such as edit, add, and delete which typically act on one or more files, and report the results on standard output. They usually only work on files within the current workspace.

  • Reporting commands such as files, filelog, and opened which do not affect files, but reports the results of the command on standard output. These commands do not necessarily depend on the current workspace.

  • Editor form commands such as submit or client (workspace) which require the user to edit a formatted temporary file with fields to specify the input, and then report the results on standard output.

  • Interactive commands such as login or resolve which prompt the user for input and then act on the results. Note that resolve could also be classified as an action command.

Logging in – an interactive command

For normal production servers you need to log in and you will be prompted to type in your password:

C:\work >p4 login
Enter password:
User bruno logged in.

Therefore, the password is specified on standard input, and the results are shown on standard output.

Action commands

Examples of these commands include the sync command which updates the current client workspace, for example:

C:\work\bruno_jam_main\depot\Jam\MAIN\src>p4 sync
//depot/Jam/MAIN/src/Build.com#8 - added as C:\work\bruno_jam_main\depot\Jam\MAIN\src\Build.com
//depot/Jam/MAIN/src/Build.mpw#1 - added as C:\work\bruno_jam_main\depot\Jam\MAIN\src\Build.mpw
//depot/Jam/MAIN/src/c.txt#1 - added as C:\work\bruno_jam_main\depot\Jam\MAIN\src\c.txt
//depot/Jam/MAIN/src/command.c#8 - added as C:\work\bruno_jam_main\depot\Jam\MAIN\src\command.c

The edit command performs the equivalent of checkout in P4V:

C:\work\bruno_jam_main\depot\Jam\MAIN\src>p4 edit Build.com
//depot/Jam/MAIN/src/Build.com#8 - opened for edit

Reporting commands

Examples of these include the opened command to show files in a pending changelist within the current workspace:

C:\work\bruno_jam_main\depot\Jam\MAIN\src>p4 opened
//depot/Jam/MAIN/src/Build.com#8 - edit default change (text)
//depot/Jam/MAIN/src/d.txt#1 - add default change (text)
//depot/Jam/MAIN/src/pathvms.c#6 - delete default change (text)

The files command shows the names of files matching the parameter:

C:\work\bruno_jam_main\depot\Jam\MAIN\src>p4 files jam*.c
//depot/Jam/MAIN/src/jam.c#35 - edit change 352 (text)
//depot/Jam/MAIN/src/jambase.c#33 - edit change 358 (text)
//depot/Jam/MAIN/src/jamgram.c#21 - edit change 351 (text)

The filelog command shows history for one or more files.

C:\work\bruno_jam_main\depot\Jam\MAIN\src>p4 filelog Build.com
//depot/Jam/MAIN/src/Build.com
... #9 change 12128 edit on 2013/08/26 by bruno@bruno_jam_main (text) 'Fix to bug 728 Removed file no '
... #8 change 12108 edit on 2013/07/31 by bruno@bruno_jam_main (text) 'Basic actions edit, add & delet'
... #7 change 346 edit on 2002/11/12 by earl@earl-dev-guava (text) 'Mucho jam reorganization in ant'
... ... branch into //depot/Jam/REL2.2/src/Build.com#1
... ... branch into //jam/main/src/Build.com#1
... #6 change 289 edit on 2001/12/21 by earl@earl-dev-yew (text) 'Changes from sybase. '
... #5 change 139 edit on 2000/05/02 by earl@earl-dev-guava (text) 'VMS DECC changes. '
... ... branch into //depot/Jam/REL2.1/src/Build.com#1
... #4 change 109 edit on 2000/02/28 by earl@earl-dev-guava (text) 'No !. '
... #3 change 81 edit on 2000/02/08 by earl@earl-dev-guava (text) 'VMS mei-larch. '
... #2 change 36 edit on 2000/01/11 by earl@earl-dev-guava (text) 'VMS ready. '
... #1 change 1 add on 1999/09/23 by earl@earl-dev-guava (text) 'Initial revision '

An editor form command – submitting a changelist

The difference with the submit command (and other similar commands) is that it requires an editor form. Because the amount of information for the command is large, when you run the command you are put into an editor for a temporary file. You modify the file, save it, and exit. P4 parses the file, and if valid, the command is executed. On Windows the default editor is Notepad.exe. This is configurable via the P4EDITOR environment variable on your operating system.

An example of a submit temporary file is:

# A Perforce Change Specification.
#
#  Change:      The change number. 'new' on a new changelist.
#  Date:        The date this specification was last modified.
#  Client:      The client on which the changelist was created.  Read-only.
#  User:        The user who created the changelist.
#  Status:      Either 'pending' or 'submitted'. Read-only.
#  Type:        Either 'public' or 'restricted'. Default is 'public'.
#  Description: Comments about the changelist.  Required.
#  Jobs:        What opened jobs are to be closed by this changelist.
#               You may delete jobs from this list.  (New changelists only.)
#  Files:       What opened files from the default changelist are to be added
#               to this changelist.  You may delete files from this list.
#               (New changelists only.)

Change:    new

Client:    bruno_jam_main

User:    bruno

Status:    new

Description:
    <enter description here>

Files:
    //depot/Jam/MAIN/src/Build.com    # edit
    //depot/Jam/MAIN/src/d.txt    # add
    //depot/Jam/MAIN/src/pathvms.c    # delete

Lines beginning with # are comment lines for information purposes only. Notice that some fields are commented to be read-only, for example, Status. If you modify the values of such fields then p4 will give an error.

We need to modify Description, and we can optionally modify some of the other fields, including deleting lines from the Files section. This would not submit them as part of this changelist, but leave them opened in the workspace.

In this instance we can modify Description to be:

Description:
    Fix to bug 728
    Removed file no longer needed.

Lines for fields such as Description must start with a space or a tab, and may be multi-line as shown previously.

When we save the file, and exit the editor, P4 shows us the results of the submit:

C:\work\bruno_jam_main\depot\Jam\MAIN\src>p4 submit
Change 12128 created with 3 open file(s).
Submitting change 12128.
Locking 3 files ...
edit //depot/Jam/MAIN/src/Build.com#9
add //depot/Jam/MAIN/src/d.txt#1
delete //depot/Jam/MAIN/src/pathvms.c#7
Change 12128 submitted.

This shows a successful submit.

Tip

Commands such as submit which take an editor form, also take parameters such as -o and –i which write the form to standard output and read it from standard input. This makes it easier for scripting. Consult the help for more information.