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 编译和测试自己的代码,并准备提交修改。在此之前,他希望使用以下命令查看更改。
[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(" "); +} + 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 尝试提交更改,使用下面的命令:
[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 提交的变化,因为Tome已经修改了库和Jerry的工作拷贝是过时了。为了避免覆盖对方的变化颠覆这个操作失败。Jerry必须更新的工作副本之前提交自己的修改。于是,他用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(" "); +} + 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。只要审查文件中的变化和目的是什么。
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 ------------------------------------------------------------------------
现在,Jerry's 工作副本与存储库同步,他可以放心地提交他的变化。
[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.