Update, Commit (with a merge)

Meanwhile, Harry has been coding as well. He heard somebody say that it’s best to compile with all the warnings turned on, so he decides to give it a try.

lottery harry$ gcc -std=c99 -Wall -Wextra -Werror lottery.c 
cc1: warnings being treated as errors
lottery.c:5: warning: unused parameter 'white_balls'
lottery.c:5: warning: unused parameter 'power_ball'

I say! The code has some warnings. The calculate_result() function isn’t using its parameters. Harry looks at the situation and realises the problem immediately: That function should be checking its arguments for validity! The power ball can be from 1 to 39 inclusive. The white balls can be 1 to 59 inclusive. So he implements the error checking.

int calculate_result(int white_balls[5], int power_ball)
{
    for (int i=0; i<5; i++)
    {
        if (
             (white_balls[i] < 1)
             || (white_balls[i] > 59)
           )
        {
            return -1;
        }
    }

    if (
         (power_ball < 1)
         || (power_ball > 39)
       )
    {
        return -1;
    }

    return 0;
}

Grand. Let’s see if it compiles.

lottery harry$ gcc -std=c99 -Wall -Wextra -Werror lottery.c

lottery harry$ ls -l
total 32
-rwxr-xr-x  1 harry  staff  8904 May 31 10:22 a.out
-rw-r--r--  1 harry  staff   843 May 31 10:22 lottery.c

Quite. But Harry decides to diff before committing, just for good measure.

lottery harry$ vv diff
=== ================
===   Modified: File @/lottery.c
--- @/lottery.c 76a16c36b9a4cea4a222ff8132f9f242fa04bed1
+++ @/lottery.c 2011/05/31 15:22:18.000 +0000
@@ -4,6 +4,25 @@
 
 int calculate_result(int white_balls[5], int power_ball)
 {
+    for (int i=0; i<5; i++)
+    {
+        if (
+             (white_balls[i] < 1)
+             || (white_balls[i] > 59)
+           )
+        {
+            return -1;
+        }
+    }
+
+    if (
+         (power_ball < 1)
+         || (power_ball > 39)
+       )
+    {
+        return -1;
+    }
+
     return 0;
 }

Good show. Time to commit the change.

lottery harry$ vv commit -m "fix some warnings"

    revision:  3:7290fd8b3372dfecf5622dec12284d602553258e
      branch:  master
         who:  harry
        when:  2011/05/31 10:23:07.968 -0500
     comment:  fix some warnings
      parent:  2:8d1b667537d569b307e320004ca7cfb10d8aea64

No problems there. This time he remembers that he needs to push his changes to the server.

But Sally has been working at the same time and she had her change ready to commit and push first.

lottery sally$ vv commit -m "change order of the command line args to be \
                              more like what the user will expect"

    revision:  3:7414ae0aa096674df94e6f3e142e893709ff3ac6
      branch:  master
         who:  sally
        when:  2011/05/31 10:23:57.285 -0500
     comment:  change order of the command line args to be more like
               what the user will expect
      parent:  2:8d1b667537d569b307e320004ca7cfb10d8aea64

lottery sally$ vv push
Pushing to http://server.futilisoft.com:8080/repos/lottery:
Pushing... Done.                                                               

So Harry tries to push his changes.

lottery harry$ vv push
vv: Error 234 (sglib): The branch needs to be merged.

What’s all this then? Veracity is not allowing Harry to push his change because it would result in the master branch having two heads.

Harry uses pull to bring in changes.

lottery harry$ vv pull
Pulling from http://server.futilisoft.com:8080/repos/lottery:
Pulling... Done.                                                               

lottery harry$ vv heads

    revision:  3:7290fd8b3372dfecf5622dec12284d602553258e
      branch:  master
         who:  harry
        when:  2011/05/31 10:23:07.968 -0500
     comment:  fix some warnings
      parent:  2:8d1b667537d569b307e320004ca7cfb10d8aea64

    revision:  4:7414ae0aa096674df94e6f3e142e893709ff3ac6
      branch:  master
         who:  sally
        when:  2011/05/31 10:23:57.285 -0500
     comment:  change order of the command line args to be more like
               what the user will expect
      parent:  2:8d1b667537d569b307e320004ca7cfb10d8aea64

lottery harry$ vv branch list
master (needs merge)

Harry can see from the output of vv heads that the master branch is now ambiguous and needs to be merged.

lottery harry$ vv merge
1 updated, 0 deleted, 0 added, 1 merged, 0 unresolved

Splendid. Now the merge is in the working copy.

lottery harry$ vv status
Modified:  @/lottery.c
   Found:  @/a.out

Everything seems to be ship-shape and Bristol fashion. Harry wants to see what happened.

lottery harry$ vv diff
=== ================
===   Modified: File @/lottery.c
--- @/lottery.c 603c9fe57661de7967b3926feb3cf29438dfcbda
+++ @/lottery.c 2011/05/31 15:24:47.000 +0000
@@ -30,16 +30,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);

Interesting. Diff shows Sally’s changes. This is because the diff was performed against changeset 7290fd8b3372dfecf5622dec12284d602553258e. Harry types vv parents to see the version of the tree on which his current pending changeset is based.

lottery harry$ vv parents

    revision:  3:7290fd8b3372dfecf5622dec12284d602553258e
      branch:  master
         who:  harry
        when:  2011/05/31 10:23:07.968 -0500
     comment:  fix some warnings
      parent:  2:8d1b667537d569b307e320004ca7cfb10d8aea64

    revision:  4:7414ae0aa096674df94e6f3e142e893709ff3ac6
      branch:  master
         who:  sally
        when:  2011/05/31 10:23:57.285 -0500
     comment:  change order of the command line args to be more like
               what the user will expect
      parent:  2:8d1b667537d569b307e320004ca7cfb10d8aea64

Because it is a merge, his working copy has two parents. The resulting DAG node will have two parents as well.

His code is already committed. Apparently Veracity was able to merge Sally’s changes directly into Harry’s modified copy of the file without any conflicts. Smashing! Let’s see if it compiles.

lottery harry$ gcc -std=c99 -Wall -Wextra -Werror lottery.c

lottery harry$ ls -l
total 32
-rwxr-xr-x  1 harry  staff  8904 May 31 10:25 a.out
-rw-r--r--  1 harry  staff   843 May 31 10:24 lottery.c

Very well then. So Harry is ready to commit the merge.

lottery harry$ vv commit -m "merge"

    revision:  5:ee2493eac8e7fc751e2b57a87a3768a192770ae3
      branch:  master
         who:  harry
        when:  2011/05/31 10:25:47.532 -0500
     comment:  merge
      parent:  3:7290fd8b3372dfecf5622dec12284d602553258e
      parent:  4:7414ae0aa096674df94e6f3e142e893709ff3ac6

And now vv parents shows only one node but that node has two parents.

lottery harry$ vv parents
Parents of pending changes in working copy:

    revision:  5:ee2493eac8e7fc751e2b57a87a3768a192770ae3
      branch:  master
         who:  harry
        when:  2011/05/31 10:25:47.532 -0500
     comment:  merge
      parent:  3:7290fd8b3372dfecf5622dec12284d602553258e
      parent:  4:7414ae0aa096674df94e6f3e142e893709ff3ac6

And push.

lottery harry$ vv push
Pushing to http://server.futilisoft.com:8080/repos/lottery:
Pushing... Done.