summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Pokorný <jpokorny@redhat.com>2013-10-10 15:17:33 +0200
committerJan Pokorný <jpokorny@redhat.com>2013-10-10 15:17:33 +0200
commit8ac6fd870d1339102155da6e75c1af9ed609dcb0 (patch)
tree570e7465341fd347c6fbae1344e775aa99565be9
parent95d2e7bd9fa4538059a94fd1f04626a46f9a14d1 (diff)
downloadpatch-fix-offsets-8ac6fd870d1339102155da6e75c1af9ed609dcb0.zip
patch-fix-offsets-8ac6fd870d1339102155da6e75c1af9ed609dcb0.tar.gz
patch-fix-offsets-8ac6fd870d1339102155da6e75c1af9ed609dcb0.tar.xz
Add proper README and patch-fix-offsets (recommended!) wrapper
Signed-off-by: Jan Pokorný <jpokorny@redhat.com>
-rw-r--r--README51
-rwxr-xr-xpatch-fix-offsets55
2 files changed, 106 insertions, 0 deletions
diff --git a/README b/README
new file mode 100644
index 0000000..49dfaac
--- /dev/null
+++ b/README
@@ -0,0 +1,51 @@
+Use case:
+
+So you have a patch that you want to backport and it's fitting well modulo
+offsets. You want convenient, non-tedious way to get perfectly fitting one.
+
+
+How to achieve it:
+
+$ patch-fix-offsets -p1 wrongoffsets.patch > goodoffsets.patch
+
+
+Alternatives:
+
+1. apply patch and rediff (possibly changing the format of the patch!)
+$ cp -R <project within which to apply the patch>{,.orig}
+$ patch -p1 <wrongoffsets.patch
+$ diff -urN <project within which to apply the patch>{.orig,} > goodoffsets.patch
+
+TBD: wiggle, merge, ...
+
+
+Tools included:
+
+fix-offsets: can either change offsets using limited expressions (DSL)
+ to specify the desired offset changes, or using its own
+ (and currently limited and buggy) method directly against
+ the target codebase -- for latter use case please refer to
+ patch-fix-offsets below
+ Note: for expression format, see fix-offsets -h
+
+patch-fix-offsets:
+ will try to apply, in a dry-run manner, the patch and based
+ on the patch utility feedback (hunk succeeded with offset X)
+ will produce an offset expression subsequently feeded into
+ fix-offsets tool
+
+
+Notable tools (with a bit different intentions, though):
+
+wiggle: http://neil.brown.name/wiggle/
+patchutils: https://git.fedorahosted.org/cgit/patchutils.git/
+Quilt: http://savannah.nongnu.org/projects/quilt
+
+Please let me know if there are others handy (surely are!) or if there is
+something better to solve use case with the as least effort (either manual
+or computational like having the whole tree externalized on the filesystem)
+as possible.
+
+--
+Jan
+jpokorn yr edha tc om
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}