Question
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;
}
Solution
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.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow