SVN - Review Changes


Advertisements


Jerry already added array.c file to the repository. Tom also checks out the latest code and starts working.

[tom@CentOS ~]$ svn co http://svn.server.com/svn/project_repo --username=tom

Above command will produce the following result.

A    project_repo/trunk
A    project_repo/trunk/array.c
A    project_repo/branches
A    project_repo/tags
Checked out revision 2.

But, he found that someone has already added the code. So he is curious about who did that and he checks the log message to see more details using the following command:

[tom@CentOS trunk]$ svn log

Above command will produce the following result.

------------------------------------------------------------------------
r2 | jerry | 2013-08-17 20:40:43 +0530 (Sat, 17 Aug 2013) | 1 line

Initial commit
------------------------------------------------------------------------
r1 | jerry | 2013-08-04 23:43:08 +0530 (Sun, 04 Aug 2013) | 1 line

Create trunk, branches, tags directory structure
------------------------------------------------------------------------

When Tom observes Jerry’s code, he immediately notices a bug in that. Jerry was not checking for array overflow, which could cause serious problems. So Tom decides to fix this problem. After modification, array.c will look like this.

#include <stdio.h>

#define MAX 16

int main(void)
{
   int i, n, arr[MAX];

   printf("Enter the total number of elements: ");
   scanf("%d", &n);

   /* handle array overflow condition */
   if (n > MAX) {
      fprintf(stderr, "Number of elements must be less than %d\n", MAX);
      return 1;
   }

   printf("Enter the elements\n");

   for (i = 0; i < n; ++i)
      scanf("%d", &arr[i]);

   printf("Array has following elements\n");
   for (i = 0; i < n; ++i)
      printf("|%d| ", arr[i]);
      printf("\n");

   return 0;
}

Tom wants to use the status operation to see the pending change-list.

[tom@CentOS trunk]$ svn status
M       array.c

array.c file is modified, that's why Subversion shows M letter before file name. Next Tom compiles and tests his code and it is working fine. Before committing changes, he wants to double-check it by reviewing the changes that he made.

[tom@CentOS trunk]$ svn diff
Index: array.c
===================================================================
--- array.c   (revision 2)
+++ array.c   (working copy)
@@ -9,6 +9,11 @@
    printf("Enter the total number of elements: ");
    scanf("%d", &n);
 
+   if (n > MAX) {
+      fprintf(stderr, "Number of elements must be less than %d\n", MAX);
+      return 1;
+   }
+
    printf("Enter the elements\n");
 
    for (i = 0; i < n; ++i)

Tom has added a few lines in the array.c file, that's why Subversion shows + sign before new lines. Now he is ready to commit his changes.

[tom@CentOS trunk]$ svn commit -m "Fix array overflow problem"

The above command will produce the following result.

Sending        trunk/array.c
Transmitting file data .
Committed revision 3.

Tom's changes are successfully committed to the repository.



Advertisements