##// END OF EJS Templates
mergestate: move commit() from base class to on-disk subclass...
Martin von Zweigbergk -
r46073:0e75c088 default
parent child Browse files
Show More
@@ -258,64 +258,6 b' class _mergestate_base(object):'
258
258
259 def commit(self):
259 def commit(self):
260 """Write current state on disk (if necessary)"""
260 """Write current state on disk (if necessary)"""
261 if self._dirty:
262 records = self._makerecords()
263 self._writerecords(records)
264 self._dirty = False
265
266 def _makerecords(self):
267 records = []
268 records.append((RECORD_LOCAL, hex(self._local)))
269 records.append((RECORD_OTHER, hex(self._other)))
270 if self.mergedriver:
271 records.append(
272 (
273 RECORD_MERGE_DRIVER_STATE,
274 b'\0'.join([self.mergedriver, self._mdstate]),
275 )
276 )
277 # Write out state items. In all cases, the value of the state map entry
278 # is written as the contents of the record. The record type depends on
279 # the type of state that is stored, and capital-letter records are used
280 # to prevent older versions of Mercurial that do not support the feature
281 # from loading them.
282 for filename, v in pycompat.iteritems(self._state):
283 if v[0] == MERGE_RECORD_DRIVER_RESOLVED:
284 # Driver-resolved merge. These are stored in 'D' records.
285 records.append(
286 (RECORD_MERGE_DRIVER_MERGE, b'\0'.join([filename] + v))
287 )
288 elif v[0] in (
289 MERGE_RECORD_UNRESOLVED_PATH,
290 MERGE_RECORD_RESOLVED_PATH,
291 ):
292 # Path conflicts. These are stored in 'P' records. The current
293 # resolution state ('pu' or 'pr') is stored within the record.
294 records.append(
295 (RECORD_PATH_CONFLICT, b'\0'.join([filename] + v))
296 )
297 elif v[1] == nullhex or v[6] == nullhex:
298 # Change/Delete or Delete/Change conflicts. These are stored in
299 # 'C' records. v[1] is the local file, and is nullhex when the
300 # file is deleted locally ('dc'). v[6] is the remote file, and
301 # is nullhex when the file is deleted remotely ('cd').
302 records.append(
303 (RECORD_CHANGEDELETE_CONFLICT, b'\0'.join([filename] + v))
304 )
305 else:
306 # Normal files. These are stored in 'F' records.
307 records.append((RECORD_MERGED, b'\0'.join([filename] + v)))
308 for filename, extras in sorted(pycompat.iteritems(self._stateextras)):
309 rawextras = b'\0'.join(
310 b'%s\0%s' % (k, v) for k, v in pycompat.iteritems(extras)
311 )
312 records.append(
313 (RECORD_FILE_VALUES, b'%s\0%s' % (filename, rawextras))
314 )
315 if self._labels is not None:
316 labels = b'\0'.join(self._labels)
317 records.append((RECORD_LABELS, labels))
318 return records
319
261
320 @staticmethod
262 @staticmethod
321 def getlocalkey(path):
263 def getlocalkey(path):
@@ -758,6 +700,66 b' class mergestate(_mergestate_base):'
758 raise
700 raise
759 return records
701 return records
760
702
703 def commit(self):
704 if self._dirty:
705 records = self._makerecords()
706 self._writerecords(records)
707 self._dirty = False
708
709 def _makerecords(self):
710 records = []
711 records.append((RECORD_LOCAL, hex(self._local)))
712 records.append((RECORD_OTHER, hex(self._other)))
713 if self.mergedriver:
714 records.append(
715 (
716 RECORD_MERGE_DRIVER_STATE,
717 b'\0'.join([self.mergedriver, self._mdstate]),
718 )
719 )
720 # Write out state items. In all cases, the value of the state map entry
721 # is written as the contents of the record. The record type depends on
722 # the type of state that is stored, and capital-letter records are used
723 # to prevent older versions of Mercurial that do not support the feature
724 # from loading them.
725 for filename, v in pycompat.iteritems(self._state):
726 if v[0] == MERGE_RECORD_DRIVER_RESOLVED:
727 # Driver-resolved merge. These are stored in 'D' records.
728 records.append(
729 (RECORD_MERGE_DRIVER_MERGE, b'\0'.join([filename] + v))
730 )
731 elif v[0] in (
732 MERGE_RECORD_UNRESOLVED_PATH,
733 MERGE_RECORD_RESOLVED_PATH,
734 ):
735 # Path conflicts. These are stored in 'P' records. The current
736 # resolution state ('pu' or 'pr') is stored within the record.
737 records.append(
738 (RECORD_PATH_CONFLICT, b'\0'.join([filename] + v))
739 )
740 elif v[1] == nullhex or v[6] == nullhex:
741 # Change/Delete or Delete/Change conflicts. These are stored in
742 # 'C' records. v[1] is the local file, and is nullhex when the
743 # file is deleted locally ('dc'). v[6] is the remote file, and
744 # is nullhex when the file is deleted remotely ('cd').
745 records.append(
746 (RECORD_CHANGEDELETE_CONFLICT, b'\0'.join([filename] + v))
747 )
748 else:
749 # Normal files. These are stored in 'F' records.
750 records.append((RECORD_MERGED, b'\0'.join([filename] + v)))
751 for filename, extras in sorted(pycompat.iteritems(self._stateextras)):
752 rawextras = b'\0'.join(
753 b'%s\0%s' % (k, v) for k, v in pycompat.iteritems(extras)
754 )
755 records.append(
756 (RECORD_FILE_VALUES, b'%s\0%s' % (filename, rawextras))
757 )
758 if self._labels is not None:
759 labels = b'\0'.join(self._labels)
760 records.append((RECORD_LABELS, labels))
761 return records
762
761 def _writerecords(self, records):
763 def _writerecords(self, records):
762 """Write current state on disk (both v1 and v2)"""
764 """Write current state on disk (both v1 and v2)"""
763 self._writerecordsv1(records)
765 self._writerecordsv1(records)
@@ -823,9 +825,6 b' class memmergestate(_mergestate_base):'
823 )
825 )
824 return None
826 return None
825
827
826 def commit(self):
827 pass
828
829
828
830 def recordupdates(repo, actions, branchmerge, getfiledata):
829 def recordupdates(repo, actions, branchmerge, getfiledata):
831 """record merge actions to the dirstate"""
830 """record merge actions to the dirstate"""
General Comments 0
You need to be logged in to leave comments. Login now