Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/merge.py @ 20589:31993cd23b11 stable
merge: change the merge state serialisation to use a record based logic
The format of the file is unchanged. But we are preparing a new file with a new
format that would be record based. So we change all the read/write logic to
handle a list of record until a very low level. This will allow simple plugging
of the new format in the current code.
author | Pierre-Yves David <pierre-yves.david@fb.com> |
---|---|
date | Thu, 27 Feb 2014 12:59:41 -0800 |
parents | 4c4cd64c754b |
children | 2b7d54e929b4 |
comparison
equal
deleted
inserted
replaced
20588:4c4cd64c754b | 20589:31993cd23b11 |
---|---|
24 self._local = node | 24 self._local = node |
25 shutil.rmtree(self._repo.join("merge"), True) | 25 shutil.rmtree(self._repo.join("merge"), True) |
26 self._dirty = False | 26 self._dirty = False |
27 def _read(self): | 27 def _read(self): |
28 self._state = {} | 28 self._state = {} |
29 records = self._readrecords() | |
30 for rtype, record in records: | |
31 if rtype == 'L': | |
32 self._local = bin(record) | |
33 elif rtype == "F": | |
34 bits = record.split("\0") | |
35 self._state[bits[0]] = bits[1:] | |
36 elif not rtype.islower(): | |
37 raise util.Abort(_('unsupported merge state record:' | |
38 % rtype)) | |
39 self._dirty = False | |
40 def _readrecords(self): | |
41 records = [] | |
29 try: | 42 try: |
30 f = self._repo.opener(self.statepath) | 43 f = self._repo.opener(self.statepath) |
31 for i, l in enumerate(f): | 44 for i, l in enumerate(f): |
32 if i == 0: | 45 if i == 0: |
33 self._local = bin(l[:-1]) | 46 records.append(('L', l[:-1])) |
34 else: | 47 else: |
35 bits = l[:-1].split("\0") | 48 records.append(('F', l[:-1])) |
36 self._state[bits[0]] = bits[1:] | |
37 f.close() | 49 f.close() |
38 except IOError, err: | 50 except IOError, err: |
39 if err.errno != errno.ENOENT: | 51 if err.errno != errno.ENOENT: |
40 raise | 52 raise |
41 self._dirty = False | 53 return records |
42 def commit(self): | 54 def commit(self): |
43 if self._dirty: | 55 if self._dirty: |
44 f = self._repo.opener(self.statepath, "w") | 56 records = [] |
45 f.write(hex(self._local) + "\n") | 57 records.append(("L", hex(self._local))) |
46 for d, v in self._state.iteritems(): | 58 for d, v in self._state.iteritems(): |
47 f.write("\0".join([d] + v) + "\n") | 59 records.append(("F", "\0".join([d] + v))) |
48 f.close() | 60 self._writerecords(records) |
49 self._dirty = False | 61 self._dirty = False |
62 def _writerecords(self, records): | |
63 f = self._repo.opener(self.statepath, "w") | |
64 irecords = iter(records) | |
65 lrecords = irecords.next() | |
66 assert lrecords[0] == 'L' | |
67 f.write(hex(self._local) + "\n") | |
68 for rtype, data in irecords: | |
69 if rtype == "F": | |
70 f.write("%s\n" % data) | |
71 f.close() | |
50 def add(self, fcl, fco, fca, fd): | 72 def add(self, fcl, fco, fca, fd): |
51 hash = util.sha1(fcl.path()).hexdigest() | 73 hash = util.sha1(fcl.path()).hexdigest() |
52 self._repo.opener.write("merge/" + hash, fcl.data()) | 74 self._repo.opener.write("merge/" + hash, fcl.data()) |
53 self._state[fd] = ['u', hash, fcl.path(), fca.path(), | 75 self._state[fd] = ['u', hash, fcl.path(), fca.path(), |
54 hex(fca.filenode()), fco.path(), fcl.flags()] | 76 hex(fca.filenode()), fco.path(), fcl.flags()] |