Show More
@@ -976,6 +976,72 b' class _InnerRevlog:' | |||
|
976 | 976 | sidedata = sidedatautil.deserialize_sidedata(segment) |
|
977 | 977 | return sidedata |
|
978 | 978 | |
|
979 | def write_entry( | |
|
980 | self, | |
|
981 | transaction, | |
|
982 | entry, | |
|
983 | data, | |
|
984 | link, | |
|
985 | offset, | |
|
986 | sidedata, | |
|
987 | sidedata_offset, | |
|
988 | index_end, | |
|
989 | data_end, | |
|
990 | sidedata_end, | |
|
991 | ): | |
|
992 | # Files opened in a+ mode have inconsistent behavior on various | |
|
993 | # platforms. Windows requires that a file positioning call be made | |
|
994 | # when the file handle transitions between reads and writes. See | |
|
995 | # 3686fa2b8eee and the mixedfilemodewrapper in windows.py. On other | |
|
996 | # platforms, Python or the platform itself can be buggy. Some versions | |
|
997 | # of Solaris have been observed to not append at the end of the file | |
|
998 | # if the file was seeked to before the end. See issue4943 for more. | |
|
999 | # | |
|
1000 | # We work around this issue by inserting a seek() before writing. | |
|
1001 | # Note: This is likely not necessary on Python 3. However, because | |
|
1002 | # the file handle is reused for reads and may be seeked there, we need | |
|
1003 | # to be careful before changing this. | |
|
1004 | if self._writinghandles is None: | |
|
1005 | msg = b'adding revision outside `revlog._writing` context' | |
|
1006 | raise error.ProgrammingError(msg) | |
|
1007 | ifh, dfh, sdfh = self._writinghandles | |
|
1008 | if index_end is None: | |
|
1009 | ifh.seek(0, os.SEEK_END) | |
|
1010 | else: | |
|
1011 | ifh.seek(index_end, os.SEEK_SET) | |
|
1012 | if dfh: | |
|
1013 | if data_end is None: | |
|
1014 | dfh.seek(0, os.SEEK_END) | |
|
1015 | else: | |
|
1016 | dfh.seek(data_end, os.SEEK_SET) | |
|
1017 | if sdfh: | |
|
1018 | sdfh.seek(sidedata_end, os.SEEK_SET) | |
|
1019 | ||
|
1020 | curr = len(self.index) - 1 | |
|
1021 | if not self.inline: | |
|
1022 | transaction.add(self.data_file, offset) | |
|
1023 | if self.sidedata_file: | |
|
1024 | transaction.add(self.sidedata_file, sidedata_offset) | |
|
1025 | transaction.add(self.index_file, curr * len(entry)) | |
|
1026 | if data[0]: | |
|
1027 | dfh.write(data[0]) | |
|
1028 | dfh.write(data[1]) | |
|
1029 | if sidedata: | |
|
1030 | sdfh.write(sidedata) | |
|
1031 | ifh.write(entry) | |
|
1032 | else: | |
|
1033 | offset += curr * self.index.entry_size | |
|
1034 | transaction.add(self.index_file, offset) | |
|
1035 | ifh.write(entry) | |
|
1036 | ifh.write(data[0]) | |
|
1037 | ifh.write(data[1]) | |
|
1038 | assert not sidedata | |
|
1039 | return ( | |
|
1040 | ifh.tell(), | |
|
1041 | dfh.tell() if dfh else None, | |
|
1042 | sdfh.tell() if sdfh else None, | |
|
1043 | ) | |
|
1044 | ||
|
979 | 1045 | |
|
980 | 1046 | class revlog: |
|
981 | 1047 | """ |
@@ -3189,7 +3255,14 b' class revlog:' | |||
|
3189 | 3255 | return self._docket.data_end |
|
3190 | 3256 | |
|
3191 | 3257 | def _writeentry( |
|
3192 | self, transaction, entry, data, link, offset, sidedata, sidedata_offset | |
|
3258 | self, | |
|
3259 | transaction, | |
|
3260 | entry, | |
|
3261 | data, | |
|
3262 | link, | |
|
3263 | offset, | |
|
3264 | sidedata, | |
|
3265 | sidedata_offset, | |
|
3193 | 3266 | ): |
|
3194 | 3267 | # Files opened in a+ mode have inconsistent behavior on various |
|
3195 | 3268 | # platforms. Windows requires that a file positioning call be made |
@@ -3203,53 +3276,29 b' class revlog:' | |||
|
3203 | 3276 | # Note: This is likely not necessary on Python 3. However, because |
|
3204 | 3277 | # the file handle is reused for reads and may be seeked there, we need |
|
3205 | 3278 | # to be careful before changing this. |
|
3206 | if self._inner._writinghandles is None: | |
|
3207 | msg = b'adding revision outside `revlog._writing` context' | |
|
3208 | raise error.ProgrammingError(msg) | |
|
3209 | ifh, dfh, sdfh = self._inner._writinghandles | |
|
3210 | if self._docket is None: | |
|
3211 | ifh.seek(0, os.SEEK_END) | |
|
3212 | else: | |
|
3213 | ifh.seek(self._docket.index_end, os.SEEK_SET) | |
|
3214 | if dfh: | |
|
3215 | if self._docket is None: | |
|
3216 | dfh.seek(0, os.SEEK_END) | |
|
3217 | else: | |
|
3218 | dfh.seek(self._docket.data_end, os.SEEK_SET) | |
|
3219 | if sdfh: | |
|
3220 | sdfh.seek(self._docket.sidedata_end, os.SEEK_SET) | |
|
3221 | ||
|
3222 | curr = len(self) - 1 | |
|
3223 | if not self._inline: | |
|
3224 | transaction.add(self._datafile, offset) | |
|
3225 | if self._sidedatafile: | |
|
3226 | transaction.add(self._sidedatafile, sidedata_offset) | |
|
3227 | transaction.add(self._indexfile, curr * len(entry)) | |
|
3228 | if data[0]: | |
|
3229 | dfh.write(data[0]) | |
|
3230 | dfh.write(data[1]) | |
|
3231 | if sidedata: | |
|
3232 | sdfh.write(sidedata) | |
|
3233 | ifh.write(entry) | |
|
3234 | else: | |
|
3235 | offset += curr * self.index.entry_size | |
|
3236 | transaction.add(self._indexfile, offset) | |
|
3237 | ifh.write(entry) | |
|
3238 | ifh.write(data[0]) | |
|
3239 | ifh.write(data[1]) | |
|
3240 | assert not sidedata | |
|
3241 | self._enforceinlinesize(transaction) | |
|
3279 | index_end = data_end = sidedata_end = None | |
|
3242 | 3280 | if self._docket is not None: |
|
3243 | # revlog-v2 always has 3 writing handles, help Pytype | |
|
3244 | wh1 = self._inner._writinghandles[0] | |
|
3245 | wh2 = self._inner._writinghandles[1] | |
|
3246 | wh3 = self._inner._writinghandles[2] | |
|
3247 | assert wh1 is not None | |
|
3248 |
|
|
|
3249 | assert wh3 is not None | |
|
3250 | self._docket.index_end = wh1.tell() | |
|
3251 | self._docket.data_end = wh2.tell() | |
|
3252 | self._docket.sidedata_end = wh3.tell() | |
|
3281 | index_end = self._docket.index_end | |
|
3282 | data_end = self._docket.data_end | |
|
3283 | sidedata_end = self._docket.sidedata_end | |
|
3284 | ||
|
3285 | files_end = self._inner.write_entry( | |
|
3286 | transaction, | |
|
3287 | entry, | |
|
3288 | data, | |
|
3289 | link, | |
|
3290 | offset, | |
|
3291 | sidedata, | |
|
3292 | sidedata_offset, | |
|
3293 | index_end, | |
|
3294 | data_end, | |
|
3295 | sidedata_end, | |
|
3296 | ) | |
|
3297 | self._enforceinlinesize(transaction) | |
|
3298 | if self._docket is not None: | |
|
3299 | self._docket.index_end = files_end[0] | |
|
3300 | self._docket.data_end = files_end[1] | |
|
3301 | self._docket.sidedata_end = files_end[2] | |
|
3253 | 3302 | |
|
3254 | 3303 | nodemaputil.setup_persistent_nodemap(transaction, self) |
|
3255 | 3304 |
General Comments 0
You need to be logged in to leave comments.
Login now