typing: make `bundlerepository` subclass `localrepository` while type checking
Currently, `mercurial/bundlerepo.py` is excluded from pytype, mostly because it
complains that various `ui` and `vfs` fields in `localrepository` are missing.
(`bundlerepository` dynamically subclasses `localrepository` when it is
instantiated, so it works at runtime.) This makes that class hierarchy known to
pytype.
Having a protocol for `Repository` is probably the right thing to do, but that
will be a lot of work and this still reflects the class at runtime. Subclassing
also has the benefit of making sure any method overrides have a matching
signature, so maybe this is a situation where we do both of these things. (I'm
not sure how clear the diagnostics are if a class *almost* implements a
protocol, but is missing a method argument or similar.) The subclassing is not
done outside of type checking runs to avoid any side effects on already complex
code.
A script that implements uppercasing all letters in a file.
$ UPPERCASEPY="$TESTTMP/uppercase.py"
$ cat > $UPPERCASEPY <<EOF
> import sys
> from mercurial.utils.procutil import setbinary
> setbinary(sys.stdin)
> setbinary(sys.stdout)
> sys.stdout.write(sys.stdin.read().upper())
> EOF
$ TESTLINES="foo\nbar\nbaz\n"
$ printf $TESTLINES | "$PYTHON" $UPPERCASEPY
FOO
BAR
BAZ
This file attempts to test our workarounds for pickle's lack of
support for short reads.
$ cat >> $HGRCPATH <<EOF
> [extensions]
> fix =
> [fix]
> uppercase-whole-file:command="$PYTHON" $UPPERCASEPY
> uppercase-whole-file:pattern=set:**
> EOF
$ hg init repo
$ cd repo
# Create a file that's large enough that it seems to not fit in
# pickle's buffer, making it use the code path that expects our
# _blockingreader's read() method to return bytes.
$ echo "some stuff" > file
$ for i in $($TESTDIR/seq.py 13); do
> cat file file > tmp
> mv -f tmp file
> done
$ hg commit -Am "add large file"
adding file
Check that we don't get a crash
$ hg fix -r .
saved backup bundle to $TESTTMP/repo/.hg/strip-backup/*-fix.hg (glob)