comparison mercurial/worker.py @ 49245:cdb85d0512b8

branching: fix wrong merge conflict resolution from 13dfad0f9f7a 13dfad0f9f7a merged stable into default, but accidentally added the _blockingreader class from stable (but deindented) instead of merging the changes from stable (2fe4efaa59af) into the existing _blockingreader class. This resulted in the _blockingreader being there two times.
author Manuel Jacob <me@manueljacob.de>
date Wed, 25 May 2022 17:23:16 +0200
parents 13dfad0f9f7a
children 5d28246b9acc
comparison
equal deleted inserted replaced
49244:13e523228623 49245:cdb85d0512b8
66 66
67 def ismainthread(): 67 def ismainthread():
68 return threading.current_thread() == threading.main_thread() 68 return threading.current_thread() == threading.main_thread()
69 69
70 70
71 class _blockingreader(object): 71 class _blockingreader:
72 def __init__(self, wrapped): 72 def __init__(self, wrapped):
73 self._wrapped = wrapped 73 self._wrapped = wrapped
74 74
75 # Do NOT implement readinto() by making it delegate to 75 # Do NOT implement readinto() by making it delegate to
76 # _wrapped.readinto(), since that is unbuffered. The unpickler is fine 76 # _wrapped.readinto(), since that is unbuffered. The unpickler is fine
88 if not ret: 88 if not ret:
89 break 89 break
90 pos += ret 90 pos += ret
91 91
92 return pos 92 return pos
93
94 def readline(self):
95 return self._wrapped.readline()
96
97 # issue multiple reads until size is fulfilled
98 def read(self, size=-1):
99 if size < 0:
100 return self._wrapped.readall()
101
102 buf = bytearray(size)
103 view = memoryview(buf)
104 pos = 0
105
106 while pos < size:
107 ret = self._wrapped.readinto(view[pos:])
108 if not ret:
109 break
110 pos += ret
111
112 del view
113 del buf[pos:]
114 return bytes(buf)
115
116
117 class _blockingreader:
118 def __init__(self, wrapped):
119 self._wrapped = wrapped
120
121 # Do NOT implement readinto() by making it delegate to
122 # _wrapped.readinto(), since that is unbuffered. The unpickler is fine
123 # with just read() and readline(), so we don't need to implement it.
124 93
125 def readline(self): 94 def readline(self):
126 return self._wrapped.readline() 95 return self._wrapped.readline()
127 96
128 # issue multiple reads until size is fulfilled 97 # issue multiple reads until size is fulfilled