summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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))