Mercurial > hg
comparison mercurial/obsolete.py @ 17075:28ed1c4511ce
obsolete: exchange obsolete marker over pushkey
For a version of the exchange, all markers are exchange. This won't
scale and we will need a better protocol later.
author | Pierre-Yves.David@ens-lyon.org |
---|---|
date | Thu, 07 Jun 2012 19:21:59 +0200 |
parents | 3a79a5682af1 |
children | 75f4180509a4 |
comparison
equal
deleted
inserted
replaced
17074:178a2e85d426 | 17075:28ed1c4511ce |
---|---|
50 string contains a key and a value, separated by a color ':', without | 50 string contains a key and a value, separated by a color ':', without |
51 additional encoding. Keys cannot contain '\0' or ':' and values | 51 additional encoding. Keys cannot contain '\0' or ':' and values |
52 cannot contain '\0'. | 52 cannot contain '\0'. |
53 """ | 53 """ |
54 import struct | 54 import struct |
55 from mercurial import util | 55 from mercurial import util, base85 |
56 from i18n import _ | 56 from i18n import _ |
57 | 57 |
58 _pack = struct.pack | 58 _pack = struct.pack |
59 _unpack = struct.unpack | 59 _unpack = struct.unpack |
60 | 60 |
164 self.successors = {} | 164 self.successors = {} |
165 | 165 |
166 def __iter__(self): | 166 def __iter__(self): |
167 return iter(self._all) | 167 return iter(self._all) |
168 | 168 |
169 def __nonzero__(self): | |
170 return bool(self._all) | |
171 | |
169 def create(self, prec, succs=(), flag=0, metadata=None): | 172 def create(self, prec, succs=(), flag=0, metadata=None): |
170 """obsolete: add a new obsolete marker | 173 """obsolete: add a new obsolete marker |
171 | 174 |
172 * ensuring it is hashable | 175 * ensuring it is hashable |
173 * check mandatory metadata | 176 * check mandatory metadata |
193 def loadmarkers(self, data): | 196 def loadmarkers(self, data): |
194 """Load all markers in data, mark them as known.""" | 197 """Load all markers in data, mark them as known.""" |
195 for marker in _readmarkers(data): | 198 for marker in _readmarkers(data): |
196 self._load(marker) | 199 self._load(marker) |
197 | 200 |
201 def mergemarkers(self, data): | |
202 other = set(_readmarkers(data)) | |
203 local = set(self._all) | |
204 new = other - local | |
205 for marker in new: | |
206 self.add(marker) | |
207 | |
198 def flushmarkers(self, stream): | 208 def flushmarkers(self, stream): |
199 """Write all markers to a stream | 209 """Write all markers to a stream |
200 | 210 |
201 After this operation, "new" markers are considered "known".""" | 211 After this operation, "new" markers are considered "known".""" |
202 self._writemarkers(stream) | 212 self._writemarkers(stream) |
207 pre, sucs = marker[:2] | 217 pre, sucs = marker[:2] |
208 self.precursors.setdefault(pre, set()).add(marker) | 218 self.precursors.setdefault(pre, set()).add(marker) |
209 for suc in sucs: | 219 for suc in sucs: |
210 self.successors.setdefault(suc, set()).add(marker) | 220 self.successors.setdefault(suc, set()).add(marker) |
211 | 221 |
212 def _writemarkers(self, stream): | 222 def _writemarkers(self, stream=None): |
213 # Kept separate from flushmarkers(), it will be reused for | 223 # Kept separate from flushmarkers(), it will be reused for |
214 # markers exchange. | 224 # markers exchange. |
215 stream.write(_pack('>B', _fmversion)) | 225 if stream is None: |
226 final = [] | |
227 w = final.append | |
228 else: | |
229 w = stream.write | |
230 w(_pack('>B', _fmversion)) | |
216 for marker in self._all: | 231 for marker in self._all: |
217 pre, sucs, flags, metadata = marker | 232 pre, sucs, flags, metadata = marker |
218 nbsuc = len(sucs) | 233 nbsuc = len(sucs) |
219 format = _fmfixed + (_fmnode * nbsuc) | 234 format = _fmfixed + (_fmnode * nbsuc) |
220 data = [nbsuc, len(metadata), flags, pre] | 235 data = [nbsuc, len(metadata), flags, pre] |
221 data.extend(sucs) | 236 data.extend(sucs) |
222 stream.write(_pack(format, *data)) | 237 w(_pack(format, *data)) |
223 stream.write(metadata) | 238 w(metadata) |
224 | 239 if stream is None: |
225 | 240 return ''.join(final) |
241 | |
242 def listmarkers(repo): | |
243 """List markers over pushkey""" | |
244 if not repo.obsstore: | |
245 return {} | |
246 data = repo.obsstore._writemarkers() | |
247 return {'dump': base85.b85encode(data)} | |
248 | |
249 def pushmarker(repo, key, old, new): | |
250 """Push markers over pushkey""" | |
251 if key != 'dump': | |
252 repo.ui.warn(_('unknown key: %r') % key) | |
253 return 0 | |
254 if old: | |
255 repo.ui.warn(_('unexpected old value') % key) | |
256 return 0 | |
257 data = base85.b85decode(new) | |
258 lock = repo.lock() | |
259 try: | |
260 repo.obsstore.mergemarkers(data) | |
261 return 1 | |
262 finally: | |
263 lock.release() | |
226 | 264 |
227 def allmarkers(repo): | 265 def allmarkers(repo): |
228 """all obsolete markers known in a repository""" | 266 """all obsolete markers known in a repository""" |
229 for markerdata in repo.obsstore: | 267 for markerdata in repo.obsstore: |
230 yield marker(repo, markerdata) | 268 yield marker(repo, markerdata) |