如何在补丁/差异文件中写注释?

时间:2013-11-22 08:54:40

标签: comments diff patch

我想回顾一下同事的补丁。我们无法使用审核工具。所以我想评论他制作的补丁文件。是否可以将内联注释写入(svn)补丁文件?

我在svn红皮书中找不到任何信息。我甚至无法找到补丁文件语法来自行解决。

1 个答案:

答案 0 :(得分:12)

diff格式只是unified diff format。如果你想要,你可以在范围信息后放一些文字。考虑使用命令svn diff -c 1544711 https://svn.apache.org/repos/asf/subversion/trunk生成的差异:

Index: subversion/mod_dav_svn/mod_dav_svn.c
===================================================================
--- subversion/mod_dav_svn/mod_dav_svn.c    (revision 1544710)
+++ subversion/mod_dav_svn/mod_dav_svn.c    (revision 1544711)
@@ -1097,7 +1097,8 @@

 /* Fill the filename on the request with a bogus path since we aren't serving
  * a file off the disk.  This means that <Directory> blocks will not match and
- * that %f in logging formats will show as "svn:/path/to/repo/path/in/repo". */
+ * %f in logging formats will show as "dav_svn:/path/to/repo/path/in/repo".
+ */
 static int dav_svn__translate_name(request_rec *r)
 {
   const char *fs_path, *repos_basename, *repos_path;
@@ -1146,7 +1147,7 @@
   if (repos_path && '/' == repos_path[0] && '\0' == repos_path[1])
     repos_path = NULL;

-  /* Combine 'svn:', fs_path and repos_path to produce the bogus path we're
+  /* Combine 'dav_svn:', fs_path and repos_path to produce the bogus path we're
    * placing in r->filename.  We can't use our standard join helpers such
    * as svn_dirent_join.  fs_path is a dirent and repos_path is a fspath
    * (that can be trivially converted to a relpath by skipping the leading
@@ -1154,7 +1155,7 @@
    * repository is 'trunk/c:hi' this results in a non canonical dirent on
    * Windows. Instead we just cat them together. */
   r->filename = apr_pstrcat(r->pool,
-                            "svn:", fs_path, repos_path, SVN_VA_NULL);
+                            "dav_svn:", fs_path, repos_path, SVN_VA_NULL);

   /* Leave a note to ourselves so that we know not to decline in the
    * map_to_storage hook. */

如果您向该命令添加选项-x-p,您将获得:

Index: subversion/mod_dav_svn/mod_dav_svn.c
===================================================================
--- subversion/mod_dav_svn/mod_dav_svn.c    (revision 1544710)
+++ subversion/mod_dav_svn/mod_dav_svn.c    (revision 1544711)
@@ -1097,7 +1097,8 @@ static int dav_svn__handler(request_rec *r)

 /* Fill the filename on the request with a bogus path since we aren't serving
  * a file off the disk.  This means that <Directory> blocks will not match and
- * that %f in logging formats will show as "svn:/path/to/repo/path/in/repo". */
+ * %f in logging formats will show as "dav_svn:/path/to/repo/path/in/repo".
+ */
 static int dav_svn__translate_name(request_rec *r)
 {
   const char *fs_path, *repos_basename, *repos_path;
@@ -1146,7 +1147,7 @@ static int dav_svn__translate_name(request_rec *r)
   if (repos_path && '/' == repos_path[0] && '\0' == repos_path[1])
     repos_path = NULL;

-  /* Combine 'svn:', fs_path and repos_path to produce the bogus path we're
+  /* Combine 'dav_svn:', fs_path and repos_path to produce the bogus path we're
    * placing in r->filename.  We can't use our standard join helpers such
    * as svn_dirent_join.  fs_path is a dirent and repos_path is a fspath
    * (that can be trivially converted to a relpath by skipping the leading
@@ -1154,7 +1155,7 @@ static int dav_svn__translate_name(request_rec *r)
    * repository is 'trunk/c:hi' this results in a non canonical dirent on
    * Windows. Instead we just cat them together. */
   r->filename = apr_pstrcat(r->pool,
-                            "svn:", fs_path, repos_path, SVN_VA_NULL);
+                            "dav_svn:", fs_path, repos_path, SVN_VA_NULL);

   /* Leave a note to ourselves so that we know not to decline in the
    * map_to_storage hook. */

注意如何在范围行上的@@之后添加该功能。任何处理diff的软件都会忽略这部分行。所以你可以自由地放置你想要的任何东西。你可以把你的评论放在那里。

Unidiff hunks用' '(空格)开始每一行表示上下文(如未更改的行),'+'表示添加的行,或'-'表示删除的行。许多解析器(包括Subversion&#s; svn patch命令)将丢弃以其他字符开头的行。因此,您可以简单地插入以其他字符开头的行。但是,这并不能保证与上述方法一样便携。