summaryrefslogtreecommitdiffstats
path: root/patch-fix-offsets
diff options
context:
space:
mode:
Diffstat (limited to 'patch-fix-offsets')
-rwxr-xr-xpatch-fix-offsets55
1 files changed, 55 insertions, 0 deletions
diff --git a/patch-fix-offsets b/patch-fix-offsets
new file mode 100755
index 0000000..b7ef3cb
--- /dev/null
+++ b/patch-fix-offsets
@@ -0,0 +1,55 @@
+#!/bin/bash
+# vim: set fileencoding=UTF-8:
+# Copyright 2013 Red Hat, Inc.
+# Author: Jan Pokorný <jpokorny at redhat dot com>
+# Licensed under MIT license
+
+set -eu
+export LC=C
+
+HERE=$(dirname "$(readlink -f "${BASH_SOURCE}")")
+
+patch_figure_expr() {
+ local line file hunk offset perfile_expr= final_expr=
+ while read line; do
+ #echo "${line}"
+ case "${line}" in
+ patching\ file\ *|@@EOF@@)
+ if test -n "$perfile_expr"; then
+ final_expr=${final_expr:+${final_expr}::}
+ final_expr+="${file}:${perfile_expr}"
+ fi
+ file=${line#patching file }
+ perfile_expr=
+ ;;
+ Hunk\ \#*\ succeeded\ at\ *\ \(offset\ *\ lines\).)
+ hunk=${line#Hunk #}
+ hunk=${hunk%% *}
+ offset=${line#* (offset }
+ offset=${offset% *}
+ perfile_expr=${perfile_expr:+${perfile_expr}:}
+ perfile_expr+="${hunk}/${offset}"
+ ;;
+ esac
+ done < <(patch -o- "$@" 2>&1 >/dev/null; echo '@@EOF@@')
+ echo "${final_expr}"
+}
+
+patches=
+args=
+cnt=1
+i=
+while test ${cnt} -le $#; do
+ i="${@:${cnt}:1}"
+ echo "${i}"
+ case "${i}" in
+ -*|--*) args+=" ${i}";;
+ *) patches+=" ${i}";;
+ esac
+ let cnt+=1
+done
+
+#echo "${patches}"
+#echo "${args}"
+#cat ${patches} | patch_figure_expr ${args}
+"${HERE}"/fix-offsets --expr "$(cat ${patches} | patch_figure_expr ${args})" ${patches}