SVN - Review 查看更改
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\n", MAX);
return 1;
}
printf("Enter the elements\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");
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\n", MAX);
+ return 1;
+ }
+
printf("Enter the elements\n");
for (i = 0; i < n; ++i)
Tom 在 array.c 文件中添加了几行,这就是 Subversion 在新行之前显示 + 符号的原因。 现在他已准备好提交更改。
[tom@CentOS trunk]$ svn commit -m "Fix array overflow problem"
The 上面的命令将产生以下结果。
Sending trunk/array.c Transmitting file data . Committed revision 3.
Tom 的 更改已成功提交到存储库。

