Skip to content

Instantly share code, notes, and snippets.

@pelya
Created October 11, 2014 01:07
Show Gist options
  • Select an option

  • Save pelya/b2e4d4f1ff361ba7b4b9 to your computer and use it in GitHub Desktop.

Select an option

Save pelya/b2e4d4f1ff361ba7b4b9 to your computer and use it in GitHub Desktop.
Split a 'normal' (non-unified) patch file with multiple files into separate small patches
#!/bin/sh
SPLITLINE="diff -r orig/"
[ -n "$1" ] && SPLITLINE="$1"
FILE=
SPLITLEN=`echo $SPLITLINE | wc -c`
while read LINE; do
if echo $LINE | grep "^$SPLITLINE" > /dev/null; then
FILE="`echo \"$LINE\" | tail -c +$SPLITLEN | sed 's@ .*@@'`"
FILE="$FILE.patch"
echo "Saving to file $FILE"
else
echo "$LINE" >> "$FILE"
fi
done
echo "Now execute:"
cat <<EOF
find -name '*.patch' -exec sh -c 'echo {} | sed "s@\(.*\)[.]patch@\1 \1.patch@" | xargs patch -n' \;
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment