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("\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编译并测试他的代码,并准备提交更改。在此之前,他想使用以下命令查看更改。
     
    [jerry@CentOS 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("\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;
     }
    
    对于新添加的行,Subversion在行前显示+号,对于已删除的行,其显示-号。现在,Jerry尝试使用以下命令来提交更改:
     
    [jerry@CentOS 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的更改,因为Tom已经修改了存储库,并且Jerry的工作副本已过期。为了避免覆盖彼此的更改,Subversion使此操作失败。杰里必须在提交更改之前更新工作副本。因此,他使用如下所示的update命令。
     
    [jerry@CentOS trunk]$ svn update
    G    array.c
    Updated to revision 3.
    
    Subversion在文件名前显示字母G,表示此文件已合并。
     
    [jerry@CentOS 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("\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仅显示Jerry的更改,但array.c文件已合并。如果仔细观察,Subversion现在显示的是修订号3。在先前的输出中,它显示的是修订号2。只需查看谁在文件中进行了更改以及出于什么目的。
     
    jerry@CentOS trunk]$ svn log
    ------------------------------------------------------------------------
    r3 | tom   | 2020-08-18 20:21:50 +0530 (Sun, 18 Aug 2020)   | 1 line
    
    Fix array overflow problem
    ------------------------------------------------------------------------
    r2 | jerry | 2020-08-17 20:40:43 +0530 (Sat, 17 Aug 2020) | 1 line
    
    Initial commit
    ------------------------------------------------------------------------
    r1 | jerry | 2020-08-04 23:43:08 +0530 (Sun, 04 Aug 2020) | 1 line
    
    Create trunk, branches, tags directory structure
    ------------------------------------------------------------------------
    
    现在,Jerry的工作副本已与存储库同步,他可以安全地提交更改。
     
    [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.