Log, Diff

Now Sally needs to set up her own working copy.

~ sally$ svn checkout svn://server.futilisoft.com/lottery
A    lottery/lottery.c
Checked out revision 1.

~ sally$ ls -l lottery
total 8
-rw-r--r--  1 sally  staff  555 Apr  6 12:41 lottery.c

When she sees that Harry has checked in the initial code they had previously discussed, Sally is happy as a coyote in the hen house. She wants to check the log to see the details.

~ sally$ cd lottery

lottery sally$ svn log
------------------------------------------------------------------------
r1 | harry | 2011-04-06 12:32:46 -0500 (Wed, 06 Apr 2011) | 1 line

initial implementation
------------------------------------------------------------------------

When Sally decides to take a look at the code, she immediately finds something that makes her nervous as a long-tailed cat in a room full of rockin’ chairs. The program expects the red ball number to be the first argument, followed by the other five. But in the actual lottery, the five white numbers are always drawn and shown first. She worries this will be confusing for users so she decides to fix it. Fortunately it is only necessary to modify a few lines of main().

    if (argc != 7)
    {
        fprintf(stderr, "Usage: %s (5 white balls) power_ball\n", argv[0]);
        return -1;
    }

    int power_ball = atoi(argv[6]);

    int white_balls[5];
    for (int i=0; i<5; i++)
    {
        white_balls[i] = atoi(argv[1+i]);
    }

Now she wants to use the status operation to see the pending changes.

lottery sally$ svn status
M       lottery.c

No surprise there. Subversion knows that lottery.c has been modified. She wants to double-check by reviewing the actual changes.

lottery sally$ svn diff
Index: lottery.c
===================================================================
--- lottery.c   (revision 1)
+++ lottery.c   (working copy)
@@ -11,16 +11,16 @@
 {
     if (argc != 7)
     {
-        fprintf(stderr, "Usage: %s power_ball (5 white balls)\n", argv[0]);
+        fprintf(stderr, "Usage: %s (5 white balls) power_ball\n", argv[0]);
         return -1;
     }
 
-    int power_ball = atoi(argv[1]);
+    int power_ball = atoi(argv[6]);
 
     int white_balls[5];
     for (int i=0; i<5; i++)
     {
-        white_balls[i] = atoi(argv[2+i]);
+        white_balls[i] = atoi(argv[1+i]);
     }
 
     int result = calculate_result(white_balls, power_ball);

Ain’t that the berries!?!

The basic svn diff command dumps output to the console in a format which is familiar to users of the standard Unix diff command. That’s the convention I’m using in this chapter. However, many users configure Subversion to bring up a visual diff app instead.