【问题标题】:How to write comments inside a patch/diff file? [duplicate]如何在补丁/差异文件中写注释? [复制]
【发布时间】:2013-11-22 08:54:40
【问题描述】:

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

我在svn red book上找不到任何信息。我什至找不到补丁文件的语法来自己弄清楚。

【问题讨论】:

  • 这实际上根本不是 SVN 特定的,并且适用于任何 .patch/.diff 文件。所以我删除了 SVN 标签,以便以更明显的方式让更多的观众使用它。

标签: comments diff patch


【解决方案1】:

差异格式只是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. */

注意函数是如何添加到范围行上的@@ 之后的。任何处理差异的软件都会忽略这部分行。所以你可以随意放任何你想要的东西。你可以把你的cmets放在那里。

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

【讨论】:

  • +1 我想补充一点,使用@@@ 进行评论很有用,这样评论中可能包含的任何内容都不会被patch 意外解析为重要。
猜你喜欢
  • 1970-01-01
  • 2020-08-18
  • 2011-11-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-10-05
  • 1970-01-01
相关资源
最近更新 更多