Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

The SVN checks for changes


May 25, 2021 SVN


Table of contents


The SVN checks for changes

Jerry adds a file called array .c warehouse. Tom checked out the last version and started working.

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

The above command will have the following effect

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

However, he found that someone had added code, and he was curious who had added it, so he checked the log information with the following command:

[tom@CentOS trunk]$ svn log

The above command will have the following effect

------------------------------------------------------------------------
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 looked at Jerry's code, he noticed a bug inside. J erry doesn't check for array overflows, which can cause serious problems. S o Tom decided to fix the problem. After the modification, the array .c will be 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 action to see a list of changes that will take effect

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

Array .c file has been modified and Subversion adds a letter M to the front of the modified file. N ext Tom compiles and tests his code and works well. He wants to check his changes again before submitting them.

[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 adds a .c lines of code to the array file, subversion adds a plus tag before the newly added lines of code, and now he's ready to submit his code.

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

The above command will have the following effect

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

Tom's changes were successfully committed to the warehouse.