##// END OF EJS Templates
merge: adds documentation to the mergestate class...
Pierre-Yves David -
r20652:2a4871c2 default
parent child Browse files
Show More
@@ -62,6 +62,11 b' class mergestate(object):'
62 62 self._dirty = False
63 63
64 64 def _read(self):
65 """Analyse each record content to restore a serialized state from disk
66
67 This function process "record" entry produced by the de-serialization
68 of on disk file.
69 """
65 70 self._state = {}
66 71 records = self._readrecords()
67 72 for rtype, record in records:
@@ -78,6 +83,19 b' class mergestate(object):'
78 83 self._dirty = False
79 84
80 85 def _readrecords(self):
86 """Read merge state from disk and return a list of record (TYPE, data)
87
88 We read data from both V1 and Ve files decide which on to use.
89
90 V1 have been used by version prior to 2.9.1 and contains less data than
91 v2. We read both version and check if no data in v2 contradict one in
92 v1. If there is not contradiction we can safely assume that both v1
93 and v2 were written at the same time and use the extract data in v2. If
94 there is contradiction we ignore v2 content as we assume an old version
95 of Mercurial have over written the mergstate file and left an old v2
96 file around.
97
98 returns list of record [(TYPE, data), ...]"""
81 99 v1records = self._readrecordsv1()
82 100 v2records = self._readrecordsv2()
83 101 oldv2 = set() # old format version of v2 record
@@ -107,6 +125,13 b' class mergestate(object):'
107 125 return v2records
108 126
109 127 def _readrecordsv1(self):
128 """read on disk merge state for version 1 file
129
130 returns list of record [(TYPE, data), ...]
131
132 Note: the "F" data from this file are one entry short
133 (no "other file node" entry)
134 """
110 135 records = []
111 136 try:
112 137 f = self._repo.opener(self.statepathv1)
@@ -122,6 +147,10 b' class mergestate(object):'
122 147 return records
123 148
124 149 def _readrecordsv2(self):
150 """read on disk merge state for version 2 file
151
152 returns list of record [(TYPE, data), ...]
153 """
125 154 records = []
126 155 try:
127 156 f = self._repo.opener(self.statepathv2)
@@ -143,6 +172,7 b' class mergestate(object):'
143 172 return records
144 173
145 174 def commit(self):
175 """Write current state on disk (if necessary)"""
146 176 if self._dirty:
147 177 records = []
148 178 records.append(("L", hex(self._local)))
@@ -153,10 +183,12 b' class mergestate(object):'
153 183 self._dirty = False
154 184
155 185 def _writerecords(self, records):
186 """Write current state on disk (both v1 and v2)"""
156 187 self._writerecordsv1(records)
157 188 self._writerecordsv2(records)
158 189
159 190 def _writerecordsv1(self, records):
191 """Write current state on disk in a version 1 file"""
160 192 f = self._repo.opener(self.statepathv1, "w")
161 193 irecords = iter(records)
162 194 lrecords = irecords.next()
@@ -168,6 +200,7 b' class mergestate(object):'
168 200 f.close()
169 201
170 202 def _writerecordsv2(self, records):
203 """Write current state on disk in a version 2 file"""
171 204 f = self._repo.opener(self.statepathv2, "w")
172 205 for key, data in records:
173 206 assert len(key) == 1
@@ -176,6 +209,14 b' class mergestate(object):'
176 209 f.close()
177 210
178 211 def add(self, fcl, fco, fca, fd):
212 """add a new (potentially?) conflicting file the merge state
213 fcl: file context for local,
214 fco: file context for remote,
215 fca: file context for ancestors,
216 fd: file path of the resulting merge.
217
218 note: also write the local version to the `.hg/merge` directory.
219 """
179 220 hash = util.sha1(fcl.path()).hexdigest()
180 221 self._repo.opener.write("merge/" + hash, fcl.data())
181 222 self._state[fd] = ['u', hash, fcl.path(),
@@ -204,6 +245,7 b' class mergestate(object):'
204 245 self._dirty = True
205 246
206 247 def resolve(self, dfile, wctx):
248 """rerun merge process for file path `dfile`"""
207 249 if self[dfile] == 'r':
208 250 return 0
209 251 stateentry = self._state[dfile]
General Comments 0
You need to be logged in to leave comments. Login now