tags:

views:

92

answers:

1

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;
 }
+2  A: 

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.

ephemient
Simple perhaps when you know how sed works ;)
shodanex
Isn't it one of the rites of passage on the road to becoming computer-literate (or at least UNIX-literate)? :)
ephemient