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

The SVN update process


May 25, 2021 SVN


Table of contents


The SVN update process

Jerry submitted his first version of the code. But he thought he should write two functions to receive input and display arrays, and after the modification, the array .c look like this.

#include <stdio.h>
#define MAX 16

void accept_input(int *arr, int n) {
   int i;
   for (i = 0; i < n; ++i) 
   scanf("%d", &arr[i]);
}

void display(int *arr, int n) {
   int i;
   for (i = 0; i < n; ++i) 
   printf("|%d| ", arr[i]);

   printf("\n");
}

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

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

   printf("Enter the elements\n");
   accept_input(arr, n);

   printf("Array has following elements\n");
   display(arr, n);

   return 0;
}

Jerry compiles and tests his code, and now he's ready to commit his changes. Previously, he wanted to see the changes with the following command.

[jerry@CentOS trunk]$ svn diff

The above command will have the following effect

Index: array.c
===================================================================
--- array.c   (revision 2)
+++ array.c   (working copy)
@@ -2,6 +2,24 @@

 #define MAX 16

+void accept_input(int *arr, int n)
+{
+   int i;
+
+   for (i = 0; i & n; ++i)
+      scanf("%d", &arr[i]);
+}
+
+void display(int *arr, int n)
+{
+   int i;
+
+   for (i = 0; i < n; ++i)
+      printf("|%d| ", arr[i]);
+   
+   printf("\n");
+}
+
 int main(void)
 {
    int i, n, arr[MAX];
@@ -10,15 +28,10 @@
    scanf("%d", &n);

    printf("Enter the elements\n");
+   accept_input(arr, 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");
+   display(arr, n);

    return 0;
 }

For the newly added line, Subversion has a plus sign on the front and marks the deleted line with a - sign. Now, Jerry tries to commit his changes using the following command:

[jerry@CentOS trunk]$ svn commit -m "Add function to accept input and to display array contents"

The above command will have the following effect

Sending        trunk/array.c
svn: Commit failed (details follow):
svn: File or directory 'array.c' is out of date; try updating
svn: resource out of date; try updating

Subversion does not allow Jerry to commit his changes because Tom has modified the repository, so Jerry's working copy is no longer valid. S ubversion does not allow him to do this in order to prevent the two men's code from being overwritten on each other. J erry must update the working copy before submitting his changes. So he used the update command, which reads:

[jerry@CentOS trunk]$ svn update
G    array.c
Updated to revision 3.

Subversion is preceded by the letter G, which means that the file has been merged.

[jerry@CentOS trunk]$ svn diff

The above command will have the following effect

Index: array.c
===================================================================
--- array.c   (revision 3)
+++ array.c   (working copy)
@@ -2,6 +2,24 @@

 #define MAX 16

+void accept_input(int *arr, int n)
+{
+   int i;
+
+   for (i = 0; i < n; ++i)
+      scanf("%d", &arr[i]);
+}
+
+void display(int *arr, int n)
+{
+   int i;
+
+   for (i = 0; i < n; ++i)
+      printf("|%d| ", arr[i]);
+   
+   printf("\n");
+}

+
 int main(void)
 {
    int i, n, arr[MAX];
@@ -15,15 +33,10 @@
    }

    printf("Enter the elements\n");
+   accept_input(arr, 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");
+   display(arr, n);

    return 0;
 }

Subversion only shows Jerry's changes, but the array .c files are merged. I f you look closely, subversion now shows a version number of 3. I n the previous output, it showed a version number of 2. It just shows who made the changes and what the purpose of the changes were.

jerry@CentOS trunk]$ svn log
------------------------------------------------------------------------
r3 | tom   | 2013-08-18 20:21:50 +0530 (Sun, 18 Aug 2013)   | 1 line

Fix array overflow problem
------------------------------------------------------------------------
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
------------------------------------------------------------------------

Now that Jerry's working directory is in sync with the repository, he can now safely commit changes.

[jerry@CentOS trunk]$ svn commit -m "Add function to accept input and to display array contents"
Sending        trunk/array.c
Transmitting file data .
Committed revision 4.