SVN Review Changes

Advertisements


Jerry already added array.c file to the repository. Tom also checkouts the latest code and starts workings.

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

Above command will produce 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 founds that, someone has already added 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 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 into that. Jerry was not checking for array overflow, this will cause serious problem. 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's 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 added few lines in 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"

Above command will produce following result

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

Tom's changes successfully committed to the repository.



Advertisements
Advertisements