SVN 审查变更
SVN 审查变更
现在,Jerry 已经将 array.c 文件已经添加到库中。Tom 也检出最新的代码,并开始工作。
[tom@CentOS ~]$ svn co http://svn.server.com/svn/project_repo --username=tom
上面命令将产生如下结果
A project_repo/trunk A project_repo/trunk/array.c A project_repo/branches A project_repo/tags Checked out revision 2.
但是,他发现有人已经添加了代码。因此,他很好奇是谁做的,并使用以下命令检查日志消息以查看更多详细信息:
[tom@CentOS trunk]$ svn log
上述命令将产生如下结果
------------------------------------------------------------------------ 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 ------------------------------------------------------------------------
当Tom观察Jerry的代码时,他立刻发现了一个错误。Jerry没有检查数组溢出,这可能会导致严重的问题。所以汤姆决定解决这个问题。修改后,array.c将会是这样的。
#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 ", MAX); return 1; } printf("Enter the elements "); 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(" "); return 0; }
Tom 要使用状态操作,看到挂起的更改列表。
[tom@CentOS trunk]$ svn status M array.c
array.c文件被修改,这就是为什么subversion在文件名之前显示m字母的原因。接下来Tom编译和测试他的代码,它工作很好。在进行更改之前,他希望通过查看他所做的更改来复查它。
[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 ", MAX); + return 1; + } + printf("Enter the elements "); for (i = 0; i < n; ++i)
Tom 补充array.c文件,这就是为什么颠覆显示+号新生产线前的几行。现在准备提交更改。
[tom@CentOS trunk]$ svn commit -m "Fix array overflow problem"
上述命令将产生如下结果
Sending trunk/array.c Transmitting file data . Committed revision 3.
Tom 的修改已经成功提交到库中。