Show More
@@ -0,0 +1,45 b'' | |||||
|
1 | A script that implements uppercasing all letters in a file. | |||
|
2 | ||||
|
3 | $ UPPERCASEPY="$TESTTMP/uppercase.py" | |||
|
4 | $ cat > $UPPERCASEPY <<EOF | |||
|
5 | > import sys | |||
|
6 | > from mercurial.utils.procutil import setbinary | |||
|
7 | > setbinary(sys.stdin) | |||
|
8 | > setbinary(sys.stdout) | |||
|
9 | > sys.stdout.write(sys.stdin.read().upper()) | |||
|
10 | > EOF | |||
|
11 | $ TESTLINES="foo\nbar\nbaz\n" | |||
|
12 | $ printf $TESTLINES | "$PYTHON" $UPPERCASEPY | |||
|
13 | FOO | |||
|
14 | BAR | |||
|
15 | BAZ | |||
|
16 | ||||
|
17 | This file attempts to test our workarounds for pickle's lack of | |||
|
18 | support for short reads. | |||
|
19 | ||||
|
20 | $ cat >> $HGRCPATH <<EOF | |||
|
21 | > [extensions] | |||
|
22 | > fix = | |||
|
23 | > [fix] | |||
|
24 | > uppercase-whole-file:command="$PYTHON" $UPPERCASEPY | |||
|
25 | > uppercase-whole-file:pattern=set:** | |||
|
26 | > EOF | |||
|
27 | ||||
|
28 | $ hg init repo | |||
|
29 | $ cd repo | |||
|
30 | ||||
|
31 | # Create a file that's large enough that it seems to not fit in | |||
|
32 | # pickle's buffer, making it use the code path that expects our | |||
|
33 | # _blockingreader's read() method to return bytes. | |||
|
34 | $ echo "some stuff" > file | |||
|
35 | $ for i in $($TESTDIR/seq.py 13); do | |||
|
36 | > cat file file > tmp | |||
|
37 | > mv -f tmp file | |||
|
38 | > done | |||
|
39 | $ hg commit -Am "add large file" | |||
|
40 | adding file | |||
|
41 | ||||
|
42 | Check that we don't get a crash | |||
|
43 | ||||
|
44 | $ hg fix -r . | |||
|
45 | saved backup bundle to $TESTTMP/repo/.hg/strip-backup/*-fix.hg (glob) |
@@ -71,8 +71,12 b' if pycompat.ispy3:' | |||||
71 | def __init__(self, wrapped): |
|
71 | def __init__(self, wrapped): | |
72 | self._wrapped = wrapped |
|
72 | self._wrapped = wrapped | |
73 |
|
73 | |||
74 | def __getattr__(self, attr): |
|
74 | # Do NOT implement readinto() by making it delegate to | |
75 | return getattr(self._wrapped, attr) |
|
75 | # _wrapped.readinto(), since that is unbuffered. The unpickler is fine | |
|
76 | # with just read() and readline(), so we don't need to implement it. | |||
|
77 | ||||
|
78 | def readline(self): | |||
|
79 | return self._wrapped.readline() | |||
76 |
|
80 | |||
77 | # issue multiple reads until size is fulfilled |
|
81 | # issue multiple reads until size is fulfilled | |
78 | def read(self, size=-1): |
|
82 | def read(self, size=-1): | |
@@ -91,7 +95,7 b' if pycompat.ispy3:' | |||||
91 |
|
95 | |||
92 | del view |
|
96 | del view | |
93 | del buf[pos:] |
|
97 | del buf[pos:] | |
94 | return buf |
|
98 | return bytes(buf) | |
95 |
|
99 | |||
96 |
|
100 | |||
97 | else: |
|
101 | else: |
General Comments 0
You need to be logged in to leave comments.
Login now