From bbabcf54676edea765053202129eac87c1c39b68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krystian=20Bac=C5=82awski?= Date: Sun, 19 May 2013 13:42:48 +0200 Subject: [PATCH] Two useful scripts for diff file manipulations. --- scripts/merge-rej.sh | 12 ++++++++++++ scripts/split-diff.sh | 26 ++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100755 scripts/merge-rej.sh create mode 100755 scripts/split-diff.sh diff --git a/scripts/merge-rej.sh b/scripts/merge-rej.sh new file mode 100755 index 0000000..1087622 --- /dev/null +++ b/scripts/merge-rej.sh @@ -0,0 +1,12 @@ +#!/bin/sh -x + +file=${1#*sources/} + +pushd "sources" > /dev/null +wiggle --replace $file $file.rej +vimdiff $file.orig $file +echo "sources/${file}.orig vs. sources/${file} -> patches/${file}.diff" +diff -du $file.orig $file | sed '1s/\.orig//' >$file.diff +popd > /dev/null + +mv -i "sources/$file.diff" "patches/$file.diff" diff --git a/scripts/split-diff.sh b/scripts/split-diff.sh new file mode 100755 index 0000000..16872ca --- /dev/null +++ b/scripts/split-diff.sh @@ -0,0 +1,26 @@ +#!/bin/sh + +# 1) Splits a patch file into smaller patches - one for each file. +# 2) Build a directory structure correspoding to paths in patch headers. +# 3) Copies smaller patches into newly created directories. +# 4) If a patch introduces a completely new file, it will be put into directory +# as a regular file and not diff file. + +[ $# == 1 ] || echo "Error: expected single patch file as an argument." +[ -f $1 ] || echo "Error: no such file '$1'." + +path="$1" + +splitdiff -a "${path}" >/dev/null + +for p in ${path}.part???; do + file=`sed -E -n -e '1s/---[[:space:]]+([^[:space:]]+).*/\1/p' ${p}` + origsize=`sed -E -n -e '3s/@@ ([^[:space:]]+) .*/\1/p' ${p}` + mkdir -p `dirname ${file}` + if [ "${origsize}" == "-0,0" ]; then + sed -E -n -e '3,$s/^\+(.*)/\1/p' ${p} >${file} + else + cp ${p} ${file}.diff + fi + rm ${p} +done