Lock, Revert

Fed up with conflicts, Sally decides to lock pb.c so only she can modify it.

The decentralized architecture required us to make certain compromises in the implementation of this feature. Obtaining a lock requires a live network connection to wherever you normally push. It is also possible to create local changesets which violate a lock about which you are not yet aware, which will result in a lock violation error later when you attempt to push those changes.

lottery sally$ vv lock src/pb.c
Pulling... Done.                                                               
Pushing... Done.                                                               

Harry updates his repository instance.

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

lottery harry$ vv update

lottery harry$ ls -l
total 32
-rw-r--r--  1 harry  staff    66 May 31 10:58 Makefile
-rwxr-xr-x  1 harry  staff  8952 May 31 10:58 pb
drwxr-xr-x  3 harry  staff   102 May 31 10:58 src

Pants! That Sally must be in a nark. She’s deleted all his email code! Harry decides to indent[36] pb.c.

lottery harry$ indent src/pb.c

lottery sally$ vv commit -m "indent our code"
vv: Error 164 (sglib): Lock violation: @/src/pb.c is locked by sally

Such a mithering. Harry calms down and reverts the changes.

In this case, the commit failed with a lock violation because Harry did a pull after Sally grabbed the lock. If he had not, the commit would have succeeded, but a subsequent attempt to push would have failed.

lottery harry$ vv revert src/pb.c

lottery harry$ vv st
   Found:  @/pb
   Found:  @/pb.c.BAK

lottery harry$ rm src/pb.c.BAK 

Sally, basking in the comfort of her lock, makes her edits. She has decided to eliminate uses of atoi(), which is deprecated.

lottery sally$ vv diff
=== ================
===   Modified: File @/src/pb.c
--- @/src/pb.c  eb093372fc2d0461465c2fbc0fef5dea54c4c898
+++ @/src/pb.c  2011/05/31 16:27:06.000 +0000
@@ -43,7 +43,14 @@
     int white_balls[5];
     for (int i=0; i<5; i++)
     {
-        white_balls[i] = atoi(argv[1+i]);
+        char* endptr = NULL;
+        long val = strtol(argv[1+i], &endptr, 10);
+        if (*endptr)
+        {
+            fprintf(stderr, "Invalid arguments\n");
+            return -1;
+        }
+        white_balls[i] = (int) val;
     }
 
     int result = calculate_result(white_balls, power_ball);

lottery sally$ make
gcc -std=c99 -Wall -Wextra -Werror pb.c -o pb

lottery sally$ ./pb 1 2 3 4 5 6
0 percent chance of winning

lottery sally$ ./pb 1 2 3e 4 5 6
Invalid arguments

And she commits her changes, lickety split.

lottery sally$ vv commit -m "use strtol. atoi is deprecated."

    revision:  17:d934a35fc8eda4fec7cb6b0d049e3881cd0e4a1d
      branch:  master
         who:  sally
        when:  2011/05/31 11:28:05.327 -0500
     comment:  use strtol. atoi is deprecated.
      parent:  16:7590c00819c05cd2103b29216350377c0746ae13

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

Veracity does not automatically remove a lock upon commit. Locks must be explicitly removed.

lottery sally$ vv unlock src/pb.c