Skip to content

Commit c1d8461

Browse files
committed
filter-repo: fix --replace-text for python3.14
Our handling of globs for --replace-text makes use of fnmatch.translate from the python standard library. Unfortunately, fnmatch.translate doesn't just give a regex that can match the given glob somewhere, it gives a regex that will only match if the string it is comparing to is exactly that glob. We need a substring search, though, so we have to use an ugly hack to butcher the returned regex from fnmatch to get it to be what we want. (It would be nice if python's fnmatch.translate() took options for what was wanted, but it doesn't.) This is fine, except that... python3.14 added '\z' as a synonym for '\Z' in regexes. No special reason, they just wanted there to be more than one way to do it. Naturally, fnmatch.translate() uses '\z' instead of '\Z', so our regex hackery in glob_to_regex() wasn't looking for the right stuff to hack off, causing the globs to fail to match text as expected. Add a python >= 3.14 hack to the existing python variation hacks in glob_to_regex() so we can handle this case too. While at it, the --replace-text test in t9394 did replacements on a literal, a glob, and a regex, but it only verified that the glob and regex replacements worked. Supplement it with a check that the literal replacement worked too. Signed-off-by: Elijah Newren <newren@gmail.com>
1 parent e81bcf3 commit c1d8461

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

git-filter-repo

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,9 @@ def glob_to_regex(glob_bytestr):
154154
regex = regex[0:-7]
155155
elif regex.startswith(r'(?s:') and regex.endswith(r')\Z'): # pragma: no cover
156156
regex = regex[4:-3]
157+
elif regex.startswith(r'(?s:') and regex.endswith(r')\z'): # pragma: no cover
158+
# Yaay, python3.14 for senselessly duplicating \Z as \z...
159+
regex = regex[4:-3]
157160

158161
# Finally, convert back to regex operating on bytestr
159162
return regex.encode()

t/t9394-filter-repo-sanity-checks-and-bigger-repo-setup.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,9 @@ test_expect_success '--replace-text all options' '
654654
git show HEAD~4:numbers/medium.num >actual &&
655655
test_cmp expect actual &&
656656
657+
echo "foodstuff" >expect &&
658+
test_cmp expect sequence/to &&
659+
657660
echo "haphazard ***REMOVED*** variation" >expect &&
658661
test_cmp expect whatever
659662
)

0 commit comments

Comments
 (0)