953 transaction - the transaction object used for rollback |
953 transaction - the transaction object used for rollback |
954 link - the linkrev data to add |
954 link - the linkrev data to add |
955 p1, p2 - the parent nodeids of the revision |
955 p1, p2 - the parent nodeids of the revision |
956 d - an optional precomputed delta |
956 d - an optional precomputed delta |
957 """ |
957 """ |
|
958 if not self.inlinedata(): |
|
959 dfh = self.opener(self.datafile, "a") |
|
960 else: |
|
961 dfh = None |
|
962 ifh = self.opener(self.indexfile, "a+") |
|
963 return self._addrevision(text, transaction, link, p1, p2, d, ifh, dfh) |
|
964 |
|
965 def _addrevision(self, text, transaction, link, p1, p2, d, ifh, dfh): |
958 if text is None: text = "" |
966 if text is None: text = "" |
959 if p1 is None: p1 = self.tip() |
967 if p1 is None: p1 = self.tip() |
960 if p2 is None: p2 = nullid |
968 if p2 is None: p2 = nullid |
961 |
969 |
962 node = hash(text, p1, p2) |
970 node = hash(text, p1, p2) |
1002 entry = struct.pack(self.indexformat, *e) |
1010 entry = struct.pack(self.indexformat, *e) |
1003 |
1011 |
1004 if not self.inlinedata(): |
1012 if not self.inlinedata(): |
1005 transaction.add(self.datafile, offset) |
1013 transaction.add(self.datafile, offset) |
1006 transaction.add(self.indexfile, n * len(entry)) |
1014 transaction.add(self.indexfile, n * len(entry)) |
1007 f = self.opener(self.datafile, "a") |
|
1008 if data[0]: |
1015 if data[0]: |
1009 f.write(data[0]) |
1016 dfh.write(data[0]) |
1010 f.write(data[1]) |
1017 dfh.write(data[1]) |
1011 f.close() |
1018 dfh.flush() |
1012 f = self.opener(self.indexfile, "a") |
1019 else: |
1013 else: |
1020 ifh.seek(0, 2) |
1014 f = self.opener(self.indexfile, "a+") |
1021 transaction.add(self.indexfile, ifh.tell(), self.count() - 1) |
1015 f.seek(0, 2) |
|
1016 transaction.add(self.indexfile, f.tell(), self.count() - 1) |
|
1017 |
1022 |
1018 if len(self.index) == 1 and self.version != REVLOGV0: |
1023 if len(self.index) == 1 and self.version != REVLOGV0: |
1019 l = struct.pack(versionformat, self.version) |
1024 l = struct.pack(versionformat, self.version) |
1020 f.write(l) |
1025 ifh.write(l) |
1021 entry = entry[4:] |
1026 entry = entry[4:] |
1022 |
1027 |
1023 f.write(entry) |
1028 ifh.write(entry) |
1024 |
1029 |
1025 if self.inlinedata(): |
1030 if self.inlinedata(): |
1026 f.write(data[0]) |
1031 ifh.write(data[0]) |
1027 f.write(data[1]) |
1032 ifh.write(data[1]) |
1028 self.checkinlinesize(transaction, f) |
1033 self.checkinlinesize(transaction, ifh) |
1029 |
1034 |
1030 self.cache = (node, n, text) |
1035 self.cache = (node, n, text) |
1031 return node |
1036 return node |
1032 |
1037 |
1033 def ancestor(self, a, b): |
1038 def ancestor(self, a, b): |
1144 if dfh: |
1149 if dfh: |
1145 dfh.flush() |
1150 dfh.flush() |
1146 ifh.flush() |
1151 ifh.flush() |
1147 text = self.revision(chain) |
1152 text = self.revision(chain) |
1148 text = self.patches(text, [delta]) |
1153 text = self.patches(text, [delta]) |
1149 chk = self.addrevision(text, transaction, link, p1, p2) |
1154 chk = self._addrevision(text, transaction, link, p1, p2, None, |
|
1155 ifh, dfh) |
|
1156 if not dfh and not self.inlinedata(): |
|
1157 # addrevision switched from inline to conventional |
|
1158 # reopen the index |
|
1159 dfh = self.opener(self.datafile, "a") |
|
1160 ifh = self.opener(self.indexfile, "a") |
1150 if chk != node: |
1161 if chk != node: |
1151 raise RevlogError(_("consistency error adding group")) |
1162 raise RevlogError(_("consistency error adding group")) |
1152 textlen = len(text) |
1163 textlen = len(text) |
1153 else: |
1164 else: |
1154 if self.version == REVLOGV0: |
1165 if self.version == REVLOGV0: |
1164 self.checkinlinesize(transaction, ifh) |
1175 self.checkinlinesize(transaction, ifh) |
1165 if not self.inlinedata(): |
1176 if not self.inlinedata(): |
1166 dfh = self.opener(self.datafile, "a") |
1177 dfh = self.opener(self.datafile, "a") |
1167 ifh = self.opener(self.indexfile, "a") |
1178 ifh = self.opener(self.indexfile, "a") |
1168 else: |
1179 else: |
1169 if not dfh: |
|
1170 # addrevision switched from inline to conventional |
|
1171 # reopen the index |
|
1172 dfh = self.opener(self.datafile, "a") |
|
1173 ifh = self.opener(self.indexfile, "a") |
|
1174 dfh.write(cdelta) |
1180 dfh.write(cdelta) |
1175 ifh.write(struct.pack(self.indexformat, *e)) |
1181 ifh.write(struct.pack(self.indexformat, *e)) |
1176 |
1182 |
1177 t, r, chain, prev = r, r + 1, node, node |
1183 t, r, chain, prev = r, r + 1, node, node |
1178 base = self.base(t) |
1184 base = self.base(t) |