summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Pokorný <jpokorny@redhat.com>2013-10-10 18:45:21 +0200
committerJan Pokorný <jpokorny@redhat.com>2013-10-10 18:46:43 +0200
commit066c4bfa18698ec40b79a90e6e5b8b69b6e1811e (patch)
treea753fa6ec1b241b1a91e000467eb2a895cbd5aa2
parent0a281baa9764f65b83a423ffed388a78499174e4 (diff)
downloadpatch-fix-offsets-066c4bfa18698ec40b79a90e6e5b8b69b6e1811e.zip
patch-fix-offsets-066c4bfa18698ec40b79a90e6e5b8b69b6e1811e.tar.gz
patch-fix-offsets-066c4bfa18698ec40b79a90e6e5b8b69b6e1811e.tar.xz
fix-offsets: teach script to do paths standardization (default)
Signed-off-by: Jan Pokorný <jpokorny@redhat.com>
-rwxr-xr-xfix-offsets32
1 files changed, 27 insertions, 5 deletions
diff --git a/fix-offsets b/fix-offsets
index 23cc1a1..82bc169 100755
--- a/fix-offsets
+++ b/fix-offsets
@@ -7,7 +7,8 @@
import sys
import re
import getopt
-from os import environ
+from os import environ, sep
+from os.path import join as path_join
from subprocess import Popen, PIPE
from threading import Thread
@@ -53,6 +54,7 @@ def proceed(opts, args):
args.append('-')
expr_dict = {}
popped = 0
+ rename = True
for i, (o, a) in enumerate(opts[:]):
if o == '--expr':
expr = opts.pop(i - popped)[1]
@@ -65,6 +67,12 @@ def proceed(opts, args):
except:
print >>sys.stderr, "invalid --expr specification"
return 1
+ elif o == '-S':
+ opts.pop(i - popped)[1]
+ rename = False
+ elif o == '-s':
+ opts.pop(i - popped)[1]
+ rename = True
cmd_args = reduce(lambda a, x: a + list(x), opts, [])
#print >>sys.stderr, "cmdargs: {0}, opts: {1}".format(cmd_args, opts)
@@ -84,8 +92,15 @@ def proceed(opts, args):
print >>sys.stderr, "Bad patch file: {0}".format(arg)
continue
for p in ps.items:
- header = '{0}--- {1}\n+++ {2}'.format('\n'.join(p.header),
- p.source, p.target)
+ header, source, target = p.header, p.source, p.target
+ if rename:
+ source = path_join('a', *(source.split(sep)[1:]))
+ target = path_join('b', *(target.split(sep)[1:]))
+ header = map(lambda x: x.replace(' ' + p.source, ' ' + source) \
+ .replace(' ' + p.target, ' ' + target),
+ header)
+ header = '{0}--- {1}\n+++ {2}'.format('\n'.join(header),
+ source, target)
print header
tres = [0 for hunk in p.hunks]
if expr_dict:
@@ -204,10 +219,17 @@ def check_and_print_hunk(i, test, hunks, tres, misorder):
if __name__ == '__main__':
# see PATCH(1)
- opts, args = getopt.getopt(sys.argv[1:], 'p:f:h', ['strip=', 'fuzz=', 'expr='])
+ opts, args = getopt.getopt(sys.argv[1:], 'p:f:' + 'sSh', ['strip=', 'fuzz='] + ['expr='])
if ('-h', '') in opts:
- print >>sys.stderr, "Usage: {0} {{[-p|-f]}} [--expr=EXPR] [patch-or-stdin]" \
+ print >>sys.stderr, "Usage: {0} [-{{sS}}] [--expr=EXPR] [PATCHOPTS] [PATCH]" \
.format(sys.argv[0])
print >>sys.stderr, " where EXPR is: FILE1:HUNK1/OFFSET1[:...][::FILE2:...]"
+ print >>sys.stderr, " currently supported PATCHOPTS: [-{{p|-f}}] + counterparts"
+ print >>sys.stderr, " and the PATCH can also be piped to stdin"
+ print >>sys.stderr, "Options of internal use (can shadow the uncommon patch ones):"
+ print >>sys.stderr, "--expr EXPR offset task specified by EXPR, see above"
+ print >>sys.stderr, "-s paths in patch follows git diff (default)"
+ print >>sys.stderr, "-S suppress paths standardization as per above"
+ print >>sys.stderr, "-h this help screen"
sys.exit(0)
sys.exit(proceed(opts, args))