comparison mercurial/revlog.py @ 2084:d66278012853

Fix transaction handling during interleaved file split.
author Chris Mason <mason@suse.com>
date Mon, 17 Apr 2006 13:19:58 -0400
parents 856f0ba200bc
children cb99c711c59f
comparison
equal deleted inserted replaced
2083:345107e167a0 2084:d66278012853
824 fp = self.opener(self.indexfile, 'r') 824 fp = self.opener(self.indexfile, 'r')
825 fp.seek(0, 2) 825 fp.seek(0, 2)
826 size = fp.tell() 826 size = fp.tell()
827 if size < 131072: 827 if size < 131072:
828 return 828 return
829 tr.add(self.datafile, 0) 829 trinfo = tr.find(self.indexfile)
830 if trinfo == None:
831 raise RevlogError(_("%s not found in the transaction" %
832 self.indexfile))
833
834 trindex = trinfo[2]
835 dataoff = self.start(trindex)
836
837 tr.add(self.datafile, dataoff)
830 df = self.opener(self.datafile, 'w') 838 df = self.opener(self.datafile, 'w')
831 calc = struct.calcsize(self.indexformat) 839 calc = struct.calcsize(self.indexformat)
832 for r in xrange(self.count()): 840 for r in xrange(self.count()):
833 start = self.start(r) + (r + 1) * calc 841 start = self.start(r) + (r + 1) * calc
834 length = self.length(r) 842 length = self.length(r)
852 fp.write(e) 860 fp.write(e)
853 861
854 # if we don't call rename, the temp file will never replace the 862 # if we don't call rename, the temp file will never replace the
855 # real index 863 # real index
856 fp.rename() 864 fp.rename()
865
866 tr.replace(self.indexfile, trindex * calc)
857 self.chunkcache = None 867 self.chunkcache = None
858 868
859 def addrevision(self, text, transaction, link, p1=None, p2=None, d=None): 869 def addrevision(self, text, transaction, link, p1=None, p2=None, d=None):
860 """add a revision to the log 870 """add a revision to the log
861 871
920 f.write(data[1]) 930 f.write(data[1])
921 f = self.opener(self.indexfile, "a") 931 f = self.opener(self.indexfile, "a")
922 else: 932 else:
923 f = self.opener(self.indexfile, "a+") 933 f = self.opener(self.indexfile, "a+")
924 f.seek(0, 2) 934 f.seek(0, 2)
925 transaction.add(self.indexfile, f.tell()) 935 transaction.add(self.indexfile, f.tell(), self.count() - 1)
926 936
927 if len(self.index) == 1 and self.version != 0: 937 if len(self.index) == 1 and self.version != 0:
928 l = struct.pack(versionformat, self.version) 938 l = struct.pack(versionformat, self.version)
929 f.write(l) 939 f.write(l)
930 entry = entry[4:] 940 entry = entry[4:]
1069 if r: 1079 if r:
1070 end = self.end(t) 1080 end = self.end(t)
1071 1081
1072 ifh = self.opener(self.indexfile, "a+") 1082 ifh = self.opener(self.indexfile, "a+")
1073 ifh.seek(0, 2) 1083 ifh.seek(0, 2)
1074 transaction.add(self.indexfile, ifh.tell()) 1084 transaction.add(self.indexfile, ifh.tell(), self.count())
1075 if self.inlinedata(): 1085 if self.inlinedata():
1076 dfh = None 1086 dfh = None
1077 else: 1087 else:
1078 transaction.add(self.datafile, end) 1088 transaction.add(self.datafile, end)
1079 dfh = self.opener(self.datafile, "a") 1089 dfh = self.opener(self.datafile, "a")