macdevcenter.com
oreilly.comSafari Books Online.Conferences.

advertisement

AddThis Social Bookmark Button

Version Control on Mac OS X, Part 2
Pages: 1, 2, 3

As you perform CVS operations such as committing and adding files, this column reflects the file status. For example, if you modify a file in your working copy, Project Builder displays an M next to the file, indicating that you've modified the local file and that it is different from the head version in CVS.



Take a quick look at Project Builder’s CVS preferences by choosing Preferences from the Project Builder menu and clicking on the CVS icon. Most of the options are straightforward, but an interesting one is the Tool for Comparisons pop-up menu. This menu enables you to choose the program that Project Builder uses to display the differences between local files and files in the repository. Currently, you can select Apple’s FileMerge program, BBEdit’s file differences feature, or a different diff tool. FileMerge, a GUI-based file comparison and merging program located in the /Developer/Applications folder, is implemented as a GUI application that uses the UNIX diff command, outputting its result to an ed script.


Project Builder enables access to CVS commands through its CVS menu. Let’s look at the commands Project Builder supports and their meaning.

  • CVS > Refresh Status - Updates the CVS status information for the selected item.
  • CVS > Update To
    • CVS > Update To > Latest, Merge w/Local – Merges the head version from CVS into the selected file.
    • CVS > Update To > Latest, Replace Local – Overwrites the working copy of the selected file with the head version.
    • CVS > Update To > Previous – Removes your local changes to the selected file and returns the originally-checked-out version.
    • CVS > Update To > Revision… - Removes your local changes to the selected file and uses a past version; Project Builder prompts you to select the version number from a list.
    • CVS > Update To > Specific Revision - Removes your local changes to the selected file and uses a past version; you are prompted to enter the version number.
  • CVS > Compare With
    • CVS > Compare With > Latest – Compares the selected file (working copy) with the head version in the repository.
    • CVS > Compare With > File… - Compares the selected file (working copy) with a file on disk; Project Builder prompts you to select a file.
    • CVS > Compare With > Previous… - Compares the selected file (working copy) with the version you checked out.
    • CVS > Compare With > Revision… - Compares the selected file (working copy) with a specific version in the CVS repository; Project Builder prompts you to select the version number from a list.
    • CVS > Compare With > Specific Revision - Compares the selected file (working copy) with a specific version in the CVS repository; Project Builder prompts you to enter the version number.
  • CVS > Add to repository… - Adds, or enrolls, the selected file (working copy) into the CVS records; you must commit the file (CVS > Commit Change) to add it to the repository.
  • CVS > Commit Changes… - Adds, or publishes, the selected file's changes to the CVS repository.
  • CVS > Show CVS – Shows a table of all files in the project with status information.
  • CVS > Cancel Pending CVS Operation – Stops a running CVS operation.
  • CVS > Disable CVS Integration – Temporarily turns off CVS support.

A common operation, not listed in the CVS menu, is removing files from the repository. To remove a file, select the file you wish to remove, press the Delete key, and follow the on-screen instructions. Another useful action is to get status information for a file. To accomplish this, choose a file from the file list, select Project > Show Info, and select the CVS tab.

Using CVS within Project Builder

Let’s look at how to use CVS and Project Builder with the sample program. To start, build MyPing (Build > Build) and run it a few times. Try pinging some sites to get a feel for how the program works.

The first change we will make is to display a default host name in the Host text field. First, click on, and open, the Classes disclosure triangle (under Files & Groups), select PingController.m, and locate the init method. This method uses three setValue messages to set the initial host name and the displayed menu items. As you can see, these messages currently set the host name to an empty string and the menu items to position 2 and 1 –- using magic numbers.


[param setValue:@"-c":@"2"];
[param setValue:@"-i":@"1"];
[param setValue:@"-host":@""];

Let’s modify this by adding three constants and setting the values to these constant values. Update the code at the beginning of PingController.m to the following code snippet (the added code is marked in bold).


#import "PingController.h"
#import "AppSupport.h"

NSString *PING_CMD = @"/sbin/ping";
NSString *PING_BUTTON_IDLE = @"Ping";
NSString *PING_BUTTON_RUNNING = @"Stop";

NSString *DEFAULT_NUM_PINGS_POS = @"2";
NSString *DEFAULT_SECS_BETWEEN_PINGS = @"1";
NSString *DEFAULT_HOST = @"localhost";

@implementation PingController

- (id) init {
  self = [super init];
  param = [[PingParameters alloc] init];
  directory = NSHomeDirectory();
  pingInProgress = NO;

  [param setValue:@"-c":DEFAULT_NUM_PINGS_POS];
  [param setValue:@"-i":DEFAULT_SECS_BETWEEN_PINGS];
  [param setValue:@"-host":DEFAULT_HOST];
  
  return self;
}

Note that after saving the file, Project Builder displays an M in the CVS column. This indicates that you've modified the file. Rebuild the program and run. Now the new host name, "localhost," appears in the Host text field.

Since you added a new feature to the program, you should to record, or commit, your change into the CVS repository. To do this, select the modified file, PingController.m, from the file list, choose CVS > Commit Changes, enter a description of the change, and click the Commit button. Project Builder adds your changes to the CVS repository. Note that project Builder has removed the M from the CVS column and updated the ID tag at the top of the file.

Another common operation is to compare two versions of a file to see what has changed between revisions. For example, to compare what has changed between the two versions of PingController.m, select PingController.m from the file list and select CVS > Compare With > Previous. Project Builder uses the tool specified in its CVS preferences to compare the files, in this case FileMerge.


click for larger view

Another common action is to view status information on a file. Once again, select PingController.m from the file list, choose Project > Show Info, and select the CVS tab.


At this point, take some time to explore Project Builder’s other CVS commands. For example, try reverting to the original version of the PingController.m file by selecting it from the file list, choosing CVS > Update To > Revision, selecting version 1.1, and clicking on Update button. Remember, your changes are not lost; they are still in CVS as the head version of the file. This command just modifies your working copy.

Final Thoughts

This concludes our brief look at using CVS under Project Builder. As you have seen, Project Builder uses CVS as its default version control system, which means if you develop under Project Builder, you owe it to yourself to learn CVS. In spite of the fact that Project Builder only supports a subset of CVS commands, it does include enough functionally to make it very useful.

In the next article, we will add a few features to MyPing and create a release using the CVS tag and branch commands. In addition, we will look at other Mac OS X GUI-based interfaces to CVS, including BBEdit and Concurrent Versions Librarian.

Kevin O'Malley is a long time Macintosh and UNIX developer. His articles have appeared in Dr. Dobb's Journal, IEEE Internet Computing, and The Perl Journal, and he is the author of Programming Mac OS X: A Guide for UNIX Developers.


Return to MacDevCenter.com