Svn 简明教程
SVN - Review Changes
Jerry 已将 array.c 文件添加到代码库中。Tom 也签出了最新代码并开始工作。
Jerry already added array.c file to the repository. Tom also checks out the latest code and starts working.
[tom@CentOS ~]$ svn co http://svn.server.com/svn/project_repo --username=tom
上述命令将产生以下结果。
Above command will produce the following result.
A project_repo/trunk
A project_repo/trunk/array.c
A project_repo/branches
A project_repo/tags
Checked out revision 2.
但他发现,有人已添加了代码。因此,他很好奇是谁这样做的,于是使用以下命令查看日志消息以了解详细信息:
But, he found that someone has already added the code. So he is curious about who did that and he checks the log message to see more details using the following command:
[tom@CentOS trunk]$ svn log
上述命令将产生以下结果。
Above command will produce the following result.
------------------------------------------------------------------------
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 的代码时,他立即注意到其中的一个 bug。Jerry 未检查数组溢出,这可能导致严重问题。因此,Tom 决定修复此问题。修改后,array.c 如下所示。
When Tom observes Jerry’s code, he immediately notices a bug in that. Jerry was not checking for array overflow, which could cause serious problems. So Tom decides to fix this problem. After modification, array.c will look like this.
#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 希望使用 status 操作 查看挂起的变更列表。
Tom wants to use the status operation to see the pending change-list.
[tom@CentOS trunk]$ svn status
M array.c
array.c 文件已修改,这就是为什么 Subversion 在文件名之前显示 M 字符的原因。接下来,Tom 编译并测试了他的代码,且该代码运行良好。在提交更改之前,他想通过查看他所做的更改来仔细检查。
array.c file is modified, that’s why Subversion shows M letter before file name. Next Tom compiles and tests his code and it is working fine. Before committing changes, he wants to double-check it by reviewing the changes that he made.
[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 has added a few lines in the array.c file, that’s why Subversion shows * + * sign before new lines. Now he is ready to commit his changes.
[tom@CentOS trunk]$ svn commit -m "Fix array overflow problem"
上述命令将产生以下结果。
The above command will produce the following result.
Sending trunk/array.c
Transmitting file data .
Committed revision 3.
Tom 的更改已成功提交到代码库中。
Tom’s changes are successfully committed to the repository.