【问题标题】:transforming patch strip level转换补丁条级别
【发布时间】:2010-11-03 16:11:29
【问题描述】:

假设我有一个可以使用 -p0 的补丁,有没有工具可以自动将此补丁转换为 -p1 补丁。例如,变换

Index: stdio-common/_i18n_number.h
===================================================================
--- stdio-common/_i18n_number.h (revision 8348)
+++ stdio-common/_i18n_number.h (working copy)
@@ -116,7 +116,7 @@ _i18n_number_rewrite (CHAR_T *w, CHAR_T
 #else

 static CHAR_T *
-_i18n_number_rewrite (CHAR_T *w, CHAR_T *rear_ptr)
+_i18n_number_rewrite (CHAR_T *w, CHAR_T *rear_ptr, CHAR_T *end)
 {
   return w;
 }

进入同一个补丁,但目录名不同(注意路径前面的a,b)

Index: stdio-common/_i18n_number.h
===================================================================
--- a/stdio-common/_i18n_number.h (revision 8348)
+++ b/stdio-common/_i18n_number.h (working copy)
@@ -116,7 +116,7 @@ _i18n_number_rewrite (CHAR_T *w, CHAR_T
 #else

 static CHAR_T *
-_i18n_number_rewrite (CHAR_T *w, CHAR_T *rear_ptr)
+_i18n_number_rewrite (CHAR_T *w, CHAR_T *rear_ptr, CHAR_T *end)
 {
   return w;
 }

【问题讨论】:

    标签: unix patch


    【解决方案1】:

    只需转换 diff 块标头中的文件名就足够了。

    sed \
        -e 's!^--- !&a/!' \
        -e 's!^+++ !&b/!' \
        < p0.patch \
        > p1.patch
    

    对于其他补丁修改工具,我建议使用patchutils,但这个工具非常简单,没有预先存在的实用程序。

    【讨论】:

    • 这难道不是成为计算机知识(或至少是 UNIX 知识)的通行仪式之一吗? :)
    猜你喜欢
    • 2016-11-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多