假设我有一个可以应用-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;
 }
有帮助吗?

解决方案

简单地转换diff块标题中的文件名就足够了。

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

对于其他补丁修改工具,我建议 patchutils ,但这个很简单它没有预先存在的效用。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top