##// END OF EJS Templates
revlog: simplify addrevision...
Matt Mackall -
r4981:e7131935 default
parent child Browse files
Show More
@@ -977,7 +977,7 b' class revlog(object):'
977 tr.replace(self.indexfile, trindex * calc)
977 tr.replace(self.indexfile, trindex * calc)
978 self._io.chunkcache = None
978 self._io.chunkcache = None
979
979
980 def addrevision(self, text, transaction, link, p1=None, p2=None, d=None):
980 def addrevision(self, text, transaction, link, p1, p2, d=None):
981 """add a revision to the log
981 """add a revision to the log
982
982
983 text - the revision data to add
983 text - the revision data to add
@@ -986,89 +986,67 b' class revlog(object):'
986 p1, p2 - the parent nodeids of the revision
986 p1, p2 - the parent nodeids of the revision
987 d - an optional precomputed delta
987 d - an optional precomputed delta
988 """
988 """
989 dfh = None
989 if not self._inline():
990 if not self._inline():
990 dfh = self.opener(self.datafile, "a")
991 dfh = self.opener(self.datafile, "a")
991 else:
992 dfh = None
993 ifh = self.opener(self.indexfile, "a+")
992 ifh = self.opener(self.indexfile, "a+")
994 return self._addrevision(text, transaction, link, p1, p2, d, ifh, dfh)
993 return self._addrevision(text, transaction, link, p1, p2, d, ifh, dfh)
995
994
996 def _addrevision(self, text, transaction, link, p1, p2, d, ifh, dfh):
995 def _addrevision(self, text, transaction, link, p1, p2, d, ifh, dfh):
997 if text is None:
998 text = ""
999 if p1 is None:
1000 p1 = self.tip()
1001 if p2 is None:
1002 p2 = nullid
1003
1004 node = hash(text, p1, p2)
996 node = hash(text, p1, p2)
1005
1006 if node in self.nodemap:
997 if node in self.nodemap:
1007 return node
998 return node
1008
999
1009 n = self.count()
1000 curr = self.count()
1010 t = n - 1
1001 prev = curr - 1
1002 base = self.base(prev)
1003 offset = self.end(prev)
1011
1004
1012 if n:
1005 if curr:
1013 base = self.base(t)
1014 start = self.start(base)
1015 end = self.end(t)
1016 if not d:
1006 if not d:
1017 prev = self.revision(self.tip())
1007 ptext = self.revision(self.node(prev))
1018 d = self.diff(prev, text)
1008 d = self.diff(ptext, text)
1019 data = compress(d)
1009 data = compress(d)
1020 l = len(data[1]) + len(data[0])
1010 l = len(data[1]) + len(data[0])
1021 dist = end - start + l
1011 dist = l + offset - self.start(base)
1022
1012
1023 # full versions are inserted when the needed deltas
1013 # full versions are inserted when the needed deltas
1024 # become comparable to the uncompressed text
1014 # become comparable to the uncompressed text
1025 if not n or dist > len(text) * 2:
1015 if not curr or dist > len(text) * 2:
1026 data = compress(text)
1016 data = compress(text)
1027 l = len(data[1]) + len(data[0])
1017 l = len(data[1]) + len(data[0])
1028 base = n
1018 base = curr
1029 else:
1030 base = self.base(t)
1031
1032 offset = 0
1033 if t >= 0:
1034 offset = self.end(t)
1035
1019
1036 e = (offset_type(offset, 0), l, len(text),
1020 e = (offset_type(offset, 0), l, len(text),
1037 base, link, self.rev(p1), self.rev(p2), node)
1021 base, link, self.rev(p1), self.rev(p2), node)
1038
1039 self.index.insert(-1, e)
1022 self.index.insert(-1, e)
1040 self.nodemap[node] = n
1023 self.nodemap[node] = curr
1041
1024
1042 if self.version == REVLOGV0:
1025 if self.version == REVLOGV0:
1043 e = (offset, l, base, link, p1, p2, node)
1026 e = (offset, l, base, link, p1, p2, node)
1044 entry = struct.pack(indexformatv0, *e)
1027 entry = struct.pack(indexformatv0, *e)
1045 else:
1028 else:
1046 entry = struct.pack(indexformatng, *e)
1029 entry = struct.pack(indexformatng, *e)
1030 if not curr:
1031 entry = struct.pack(versionformat, self.version) + entry[4:]
1047
1032
1048 if not self._inline():
1033 if not self._inline():
1049 transaction.add(self.datafile, offset)
1034 transaction.add(self.datafile, offset)
1050 transaction.add(self.indexfile, n * len(entry))
1035 transaction.add(self.indexfile, curr * len(entry))
1051 if data[0]:
1036 if data[0]:
1052 dfh.write(data[0])
1037 dfh.write(data[0])
1053 dfh.write(data[1])
1038 dfh.write(data[1])
1054 dfh.flush()
1039 dfh.flush()
1040 ifh.write(entry)
1055 else:
1041 else:
1056 ifh.seek(0, 2)
1042 ifh.seek(0, 2)
1057 transaction.add(self.indexfile, ifh.tell(), self.count() - 1)
1043 transaction.add(self.indexfile, ifh.tell(), prev)
1058
1059 if self.count() == 1 and self.version != REVLOGV0:
1060 l = struct.pack(versionformat, self.version)
1061 ifh.write(l)
1062 entry = entry[4:]
1063
1064 ifh.write(entry)
1044 ifh.write(entry)
1065
1066 if self._inline():
1067 ifh.write(data[0])
1045 ifh.write(data[0])
1068 ifh.write(data[1])
1046 ifh.write(data[1])
1069 self.checkinlinesize(transaction, ifh)
1047 self.checkinlinesize(transaction, ifh)
1070
1048
1071 self.cache = (node, n, text)
1049 self.cache = (node, curr, text)
1072 return node
1050 return node
1073
1051
1074 def ancestor(self, a, b):
1052 def ancestor(self, a, b):
General Comments 0
You need to be logged in to leave comments. Login now