aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEdward Welbourne <edward.welbourne@qt.io>2019-08-29 11:22:30 +0200
committerEdward Welbourne <edward.welbourne@qt.io>2019-09-09 17:49:44 +0000
commitbc576a1348d026e5a8653bfed9447b98c7a20a4f (patch)
tree01fe7c4b9ac9fe695135a150be42fbbddb8c6219
parente142767349c6f7706ce554fdf54d13a5fb21fbbb (diff)
Fix some indexing issues in resetboring.py
If we're too near to the end of a token list to accommodate a match to a sequence of words, we can stop searching (else we IndexError). When replacing one sequence of tokens with another, the search for more matches for the former is using the indexing in the token list we started with, before the first replacement. If the replacement's length doesn't match the original, we need to adjust match positions to take that into account. Change-Id: I727576c047be7bfaf047b618c5bc49604e3e7aad Reviewed-by: Frederik Gladhorn <frederik.gladhorn@qt.io>
-rwxr-xr-xpackaging-tools/resetboring.py5
1 files changed, 5 insertions, 0 deletions
diff --git a/packaging-tools/resetboring.py b/packaging-tools/resetboring.py
index 1d133f979..a9f01e8c6 100755
--- a/packaging-tools/resetboring.py
+++ b/packaging-tools/resetboring.py
@@ -685,6 +685,8 @@ class Selector(object): # Select interesting changes, discard boring.
ind = 0
while True:
ind = words.index(after[0], ind)
+ if len(words) < ind + len(after):
+ break # definitely doesn't match, here or later
if all(words[i + ind] == tok for i, tok in enumerate(after)):
yield ind
ind += 1
@@ -695,8 +697,11 @@ class Selector(object): # Select interesting changes, discard boring.
return True
return False
def purge(words, pair=swap, get=find):
+ offset, step = 0, len(pair[0]) - len(pair[1])
for ind in get(words):
+ ind += offset # Correct for earlier edits
words[ind : ind + len(pair[1])] = pair[0]
+ offset += step # Update the correction
return words
yield test, purge