transforming patch strip level

邮差的信 提交于 2019-12-11 04:29:37

问题


Suppose I have a patch that can be applied with -p0, is there a tool to automatically transform this patch into a -p1 patch. For example, transforming

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;
 }

Into the same patch but with different directory name (notice the a, b) in front of the path

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;
 }

回答1:


Simply transforming the filenames in the diff chunk headers is good enough.

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

For other patch mangling tools, I'd suggest patchutils, but this one is so simple that there's no pre-existing utility for it.



来源:https://stackoverflow.com/questions/1007114/transforming-patch-strip-level

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!