SVN更新過程


Jerry 提交第一個版本的程式碼。但他認為,他應該寫兩個函式接受輸入和顯示陣列的內容。修改後array.c 的樣子。

#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("
");
}

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

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

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

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

   return 0;
}

Jerry 編譯和測試自己的程式碼,並準備提交修改。在此之前,他希望使用以下命令檢視更改。

[[email protected] trunk]$ svn diff

上面的命令將產生以下結果

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("
");
+}
+
 int main(void)
 {
    int i, n, arr[MAX];
@@ -10,15 +28,10 @@
    scanf("%d", &n);
 
    printf("Enter the elements
");
+   accept_input(arr, n);
 
-   for (i = 0; i < n; ++i)
-      scanf("%d", &arr[i]);
-
    printf("Array has following elements
");
-   for (i = 0; i < n; ++i)
-      printf("|%d| ", arr[i]);
-   
-   printf("
");
+   display(arr, n);
 
    return 0;
 }

對於新新增的行顛覆顯示+符號, - 符號前行為刪除行的顯示。Jerry 嘗試提交更改,使用下面的命令:

[[email protected] trunk]$ svn commit -m "Add function to accept input and to display array contents"

上面的命令將產生以下結果

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是不允許Jerry 提交的變化,因為Tome已經修改了庫和Jerry的工作拷貝是過時了。為了避免覆蓋對方的變化顛覆這個操作失敗。Jerry必須更新的工作副本之前提交自己的修改。於是,他用update命令

[[email protected] trunk]$ svn update
G    array.c
Updated to revision 3.

Subversion 顯示檔案名前G 字母,這意味著此檔案已被合併。

[[email protected] trunk]$ svn diff

上面的命令將產生以下結果

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("
");
+}

+
 int main(void)
 {
    int i, n, arr[MAX];
@@ -15,15 +33,10 @@
    }
 
    printf("Enter the elements
");
+   accept_input(arr, n);
 
-   for (i = 0; i < n; ++i)
-      scanf("%d", &arr[i]);
-
    printf("Array has following elements
");
-   for (i = 0; i < n; ++i)
-      printf("|%d| ", arr[i]);
-   
-   printf("
");
+   display(arr, n);
 
    return 0;
 }

Subversion是只顯示Jerry 的變化。但array.c的檔案合併,如果觀察仔細Subversion的現在修訂號為3,在以前的輸出顯示修訂號為2。只要審查檔案中的變化和目的是什麼。

[email protected] 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
------------------------------------------------------------------------

現在,Jerry's 工作副本與儲存庫同步,他可以放心地提交他的變化。

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