##// END OF EJS Templates
revlog: only use the `_indexfp` method for read operation...
marmoute -
r47993:ffa8afc5 default
parent child Browse files
Show More
@@ -613,14 +613,33 b' class revlog(object):'
613 engine = util.compengines[self._compengine]
613 engine = util.compengines[self._compengine]
614 return engine.revlogcompressor(self._compengineopts)
614 return engine.revlogcompressor(self._compengineopts)
615
615
616 def _indexfp(self, mode=b'r'):
616 def _indexfp(self):
617 """file object for the revlog's index file"""
617 """file object for the revlog's index file"""
618 args = {'mode': mode}
618 return self.opener(self._indexfile, mode=b"r")
619 if mode != b'r':
619
620 args['checkambig'] = self._checkambig
620 def __index_write_fp(self):
621 if mode == b'w':
621 # You should not use this directly and use `_writing` instead
622 args['atomictemp'] = True
622 try:
623 return self.opener(self._indexfile, **args)
623 f = self.opener(
624 self._indexfile, mode=b"r+", checkambig=self._checkambig
625 )
626 f.seek(0, os.SEEK_END)
627 return f
628 except IOError as inst:
629 if inst.errno != errno.ENOENT:
630 raise
631 return self.opener(
632 self._indexfile, mode=b"w+", checkambig=self._checkambig
633 )
634
635 def __index_new_fp(self):
636 # You should not use this unless you are upgrading from inline revlog
637 return self.opener(
638 self._indexfile,
639 mode=b"w",
640 checkambig=self._checkambig,
641 atomictemp=True,
642 )
624
643
625 def _datafp(self, mode=b'r'):
644 def _datafp(self, mode=b'r'):
626 """file object for the revlog's data file"""
645 """file object for the revlog's data file"""
@@ -1990,14 +2009,14 b' class revlog(object):'
1990 new_dfh = self._datafp(b'w+')
2009 new_dfh = self._datafp(b'w+')
1991 new_dfh.truncate(0) # drop any potentially existing data
2010 new_dfh.truncate(0) # drop any potentially existing data
1992 try:
2011 try:
1993 with self._indexfp(b'r') as read_ifh:
2012 with self._indexfp() as read_ifh:
1994 for r in self:
2013 for r in self:
1995 new_dfh.write(self._getsegmentforrevs(r, r, df=read_ifh)[1])
2014 new_dfh.write(self._getsegmentforrevs(r, r, df=read_ifh)[1])
1996 if troffset <= self.start(r):
2015 if troffset <= self.start(r):
1997 trindex = r
2016 trindex = r
1998 new_dfh.flush()
2017 new_dfh.flush()
1999
2018
2000 with self.opener(self._indexfile, mode=b'w', atomictemp=True) as fp:
2019 with self.__index_new_fp() as fp:
2001 self._format_flags &= ~FLAG_INLINE_DATA
2020 self._format_flags &= ~FLAG_INLINE_DATA
2002 self._inline = False
2021 self._inline = False
2003 for i in self:
2022 for i in self:
@@ -2016,7 +2035,7 b' class revlog(object):'
2016
2035
2017 if existing_handles:
2036 if existing_handles:
2018 # switched from inline to conventional reopen the index
2037 # switched from inline to conventional reopen the index
2019 ifh = self._indexfp(b"r+")
2038 ifh = self.__index_write_fp()
2020 self._writinghandles = (ifh, new_dfh)
2039 self._writinghandles = (ifh, new_dfh)
2021 new_dfh = None
2040 new_dfh = None
2022 finally:
2041 finally:
@@ -2047,13 +2066,7 b' class revlog(object):'
2047 transaction.add(self._datafile, dsize)
2066 transaction.add(self._datafile, dsize)
2048 try:
2067 try:
2049 isize = r * self.index.entry_size
2068 isize = r * self.index.entry_size
2050 try:
2069 ifh = self.__index_write_fp()
2051 ifh = self._indexfp(b"r+")
2052 ifh.seek(0, os.SEEK_END)
2053 except IOError as inst:
2054 if inst.errno != errno.ENOENT:
2055 raise
2056 ifh = self._indexfp(b"w+")
2057 if self._inline:
2070 if self._inline:
2058 transaction.add(self._indexfile, dsize + isize)
2071 transaction.add(self._indexfile, dsize + isize)
2059 else:
2072 else:
General Comments 0
You need to be logged in to leave comments. Login now