Lets use a single try, with conditional cleanup. This make is easier to add a
file handle dedicated to sidedata.
Details
Details
Diff Detail
Diff Detail
- Repository
- rHG Mercurial
- Branch
- default
- Lint
No Linters Available - Unit
No Unit Test Coverage
( )
Lets use a single try, with conditional cleanup. This make is easier to add a
file handle dedicated to sidedata.
| No Linters Available |
| No Unit Test Coverage |
| def _writing(self, transaction): | def _writing(self, transaction): | ||||
| if self._trypending: | if self._trypending: | ||||
| msg = b'try to write in a `trypending` revlog: %s' | msg = b'try to write in a `trypending` revlog: %s' | ||||
| msg %= self.display_id | msg %= self.display_id | ||||
| raise error.ProgrammingError(msg) | raise error.ProgrammingError(msg) | ||||
| if self._writinghandles is not None: | if self._writinghandles is not None: | ||||
| yield | yield | ||||
| else: | else: | ||||
| ifh = dfh = None | |||||
| try: | |||||
| r = len(self) | r = len(self) | ||||
| # opening the data file. | |||||
| dsize = 0 | dsize = 0 | ||||
| if r: | if r: | ||||
| dsize = self.end(r - 1) | dsize = self.end(r - 1) | ||||
| dfh = None | dfh = None | ||||
| if not self._inline: | if not self._inline: | ||||
| try: | try: | ||||
| dfh = self._datafp(b"r+") | dfh = self._datafp(b"r+") | ||||
| if self._docket is None: | if self._docket is None: | ||||
| dfh.seek(0, os.SEEK_END) | dfh.seek(0, os.SEEK_END) | ||||
| else: | else: | ||||
| dfh.seek(self._docket.data_end, os.SEEK_SET) | dfh.seek(self._docket.data_end, os.SEEK_SET) | ||||
| except IOError as inst: | except IOError as inst: | ||||
| if inst.errno != errno.ENOENT: | if inst.errno != errno.ENOENT: | ||||
| raise | raise | ||||
| dfh = self._datafp(b"w+") | dfh = self._datafp(b"w+") | ||||
| transaction.add(self._datafile, dsize) | transaction.add(self._datafile, dsize) | ||||
| try: | |||||
| # opening the index file. | |||||
| isize = r * self.index.entry_size | isize = r * self.index.entry_size | ||||
| ifh = self.__index_write_fp() | ifh = self.__index_write_fp() | ||||
| if self._inline: | if self._inline: | ||||
| transaction.add(self._indexfile, dsize + isize) | transaction.add(self._indexfile, dsize + isize) | ||||
| else: | else: | ||||
| transaction.add(self._indexfile, isize) | transaction.add(self._indexfile, isize) | ||||
| try: | # exposing all file handle for writing. | ||||
| self._writinghandles = (ifh, dfh) | self._writinghandles = (ifh, dfh) | ||||
| try: | |||||
| yield | yield | ||||
| if self._docket is not None: | if self._docket is not None: | ||||
| self._write_docket(transaction) | self._write_docket(transaction) | ||||
| finally: | finally: | ||||
| self._writinghandles = None | self._writinghandles = None | ||||
| finally: | if ifh is not None: | ||||
| ifh.close() | ifh.close() | ||||
| finally: | |||||
| if dfh is not None: | if dfh is not None: | ||||
| dfh.close() | dfh.close() | ||||
| def _write_docket(self, transaction): | def _write_docket(self, transaction): | ||||
| """write the current docket on disk | """write the current docket on disk | ||||
| Exist as a method to help changelog to implement transaction logic | Exist as a method to help changelog to implement transaction logic | ||||