Low-level wrapper for streaming blob content. The underlying libgit2 git_writestream filter chain will be run in a separate thread. The GIL will be released while running libgit2 filtering.
| 10 | |
| 11 | |
| 12 | class _BlobIO(io.RawIOBase): |
| 13 | """Low-level wrapper for streaming blob content. |
| 14 | |
| 15 | The underlying libgit2 git_writestream filter chain will be run |
| 16 | in a separate thread. The GIL will be released while running |
| 17 | libgit2 filtering. |
| 18 | """ |
| 19 | |
| 20 | def __init__( |
| 21 | self, |
| 22 | blob: Blob, |
| 23 | as_path: Optional[str] = None, |
| 24 | flags: BlobFilter = BlobFilter.CHECK_FOR_BINARY, |
| 25 | commit_id: Optional[Oid] = None, |
| 26 | ): |
| 27 | super().__init__() |
| 28 | self._blob = blob |
| 29 | self._queue: Optional[Queue] = Queue(maxsize=1) |
| 30 | self._ready = threading.Event() |
| 31 | self._writer_closed = threading.Event() |
| 32 | self._chunk: Optional[bytes] = None |
| 33 | self._thread = threading.Thread( |
| 34 | target=self._blob._write_to_queue, |
| 35 | args=(self._queue, self._ready, self._writer_closed), |
| 36 | kwargs={ |
| 37 | 'as_path': as_path, |
| 38 | 'flags': int(flags), |
| 39 | 'commit_id': commit_id, |
| 40 | }, |
| 41 | daemon=True, |
| 42 | ) |
| 43 | self._thread.start() |
| 44 | |
| 45 | def __exit__(self, exc_type, exc_value, traceback): |
| 46 | self.close() |
| 47 | |
| 48 | def isatty(self): |
| 49 | return False |
| 50 | |
| 51 | def readable(self): |
| 52 | return True |
| 53 | |
| 54 | def writable(self): |
| 55 | return False |
| 56 | |
| 57 | def seekable(self): |
| 58 | return False |
| 59 | |
| 60 | def readinto(self, b, /): |
| 61 | try: |
| 62 | while self._chunk is None: |
| 63 | self._ready.wait() |
| 64 | if self._queue.empty(): |
| 65 | if self._writer_closed.is_set(): |
| 66 | # EOF |
| 67 | return 0 |
| 68 | self._ready.clear() |
| 69 | time.sleep(0) |
no outgoing calls
no test coverage detected
searching dependent graphs…