comparison mercurial/revlog.py @ 12023:44c22dc193a4

revlog.addrevision(): move computation of nodeid in addrevision() The check "if node in nodemap" is already done earlier in addgroup().
author Benoit Boissinot <benoit.boissinot@ens-lyon.org>
date Sun, 22 Aug 2010 23:17:17 +0200
parents bade7a9c5c07
children 56a7721ee3ec
comparison
equal deleted inserted replaced
12022:6b04f1e1aa8a 12023:44c22dc193a4
1135 transaction - the transaction object used for rollback 1135 transaction - the transaction object used for rollback
1136 link - the linkrev data to add 1136 link - the linkrev data to add
1137 p1, p2 - the parent nodeids of the revision 1137 p1, p2 - the parent nodeids of the revision
1138 cachedelta - an optional precomputed delta 1138 cachedelta - an optional precomputed delta
1139 """ 1139 """
1140 node = hash(text, p1, p2)
1141 if (node in self.nodemap and
1142 (not self.flags(self.rev(node)) & REVIDX_PUNCHED_FLAG)):
1143 return node
1144
1140 dfh = None 1145 dfh = None
1141 if not self._inline: 1146 if not self._inline:
1142 dfh = self.opener(self.datafile, "a") 1147 dfh = self.opener(self.datafile, "a")
1143 ifh = self.opener(self.indexfile, "a+") 1148 ifh = self.opener(self.indexfile, "a+")
1144 try: 1149 try:
1145 return self._addrevision(text, transaction, link, p1, p2, 1150 return self._addrevision(node, text, transaction, link, p1, p2,
1146 cachedelta, ifh, dfh) 1151 cachedelta, ifh, dfh)
1147 finally: 1152 finally:
1148 if dfh: 1153 if dfh:
1149 dfh.close() 1154 dfh.close()
1150 ifh.close() 1155 ifh.close()
1151 1156
1152 def _addrevision(self, text, transaction, link, p1, p2, 1157 def _addrevision(self, node, text, transaction, link, p1, p2,
1153 cachedelta, ifh, dfh): 1158 cachedelta, ifh, dfh):
1154 node = hash(text, p1, p2)
1155 if (node in self.nodemap and
1156 (not self.flags(self.rev(node)) & REVIDX_PUNCHED_FLAG)):
1157 return node
1158
1159 curr = len(self) 1159 curr = len(self)
1160 prev = curr - 1 1160 prev = curr - 1
1161 base = curr 1161 base = curr
1162 offset = self.end(prev) 1162 offset = self.end(prev)
1163 flags = 0 1163 flags = 0
1358 # text == '' in the case of nullrev or punched revision 1358 # text == '' in the case of nullrev or punched revision
1359 text = buffer(delta, 12) 1359 text = buffer(delta, 12)
1360 else: 1360 else:
1361 text = mdiff.patches(text, [delta]) 1361 text = mdiff.patches(text, [delta])
1362 del delta 1362 del delta
1363 chk = self._addrevision(text, transaction, link, p1, p2, None, 1363 chk = self._addrevision(node, text, transaction, link,
1364 ifh, dfh) 1364 p1, p2, None, ifh, dfh)
1365 if not dfh and not self._inline: 1365 if not dfh and not self._inline:
1366 # addrevision switched from inline to conventional 1366 # addrevision switched from inline to conventional
1367 # reopen the index 1367 # reopen the index
1368 dfh = self.opener(self.datafile, "a") 1368 dfh = self.opener(self.datafile, "a")
1369 ifh = self.opener(self.indexfile, "a") 1369 ifh = self.opener(self.indexfile, "a")