Mercurial > evolve
comparison hgext/states.py @ 55:cf4626a13345
Update pushkey code to be able to push ready heads too.
author | Pierre-Yves David <pierre-yves.david@logilab.fr> |
---|---|
date | Thu, 08 Sep 2011 19:03:42 +0200 |
parents | ad1a4fb0fc49 |
children | 62f2fe22bd42 |
comparison
equal
deleted
inserted
replaced
54:ad1a4fb0fc49 | 55:cf4626a13345 |
---|---|
91 ST2 = state('draft', _NOSHARE | _MUTABLE) | 91 ST2 = state('draft', _NOSHARE | _MUTABLE) |
92 ST1 = state('ready', _MUTABLE, next=ST2) | 92 ST1 = state('ready', _MUTABLE, next=ST2) |
93 ST0 = state('published', next=ST1) | 93 ST0 = state('published', next=ST1) |
94 | 94 |
95 STATES = (ST0, ST1, ST2) | 95 STATES = (ST0, ST1, ST2) |
96 STATESMAP =dict([(st.name, st) for st in STATES]) | |
96 | 97 |
97 @util.cachefunc | 98 @util.cachefunc |
98 def laststatewithout(prop): | 99 def laststatewithout(prop): |
99 for state in STATES: | 100 for state in STATES: |
100 if not state.properties & prop: | 101 if not state.properties & prop: |
175 cmdtable[state.name] = (cmdmoveheads, [], '<revset>') | 176 cmdtable[state.name] = (cmdmoveheads, [], '<revset>') |
176 | 177 |
177 # Pushkey mechanism for mutable | 178 # Pushkey mechanism for mutable |
178 ######################################### | 179 ######################################### |
179 | 180 |
180 def pushimmutableheads(repo, key, old, new): | 181 def pushstatesheads(repo, key, old, new): |
181 st = ST0 | 182 st = STATESMAP[new] |
182 w = repo.wlock() | 183 w = repo.wlock() |
183 try: | 184 try: |
184 newhead = node.bin(key) | 185 newhead = node.bin(key) |
185 repo[newhead] | 186 repo[newhead] |
186 repo.setstate(ST0, [newhead]) | 187 repo.setstate(st, [newhead]) |
187 finally: | 188 finally: |
188 w.release() | 189 w.release() |
189 | 190 |
190 def listimmutableheads(repo): | 191 def liststatesheads(repo): |
191 return dict.fromkeys(map(node.hex, repo.stateheads(ST0)), '1') | 192 keys = {} |
192 | 193 for state in [st for st in STATES if st.trackheads]: |
193 pushkey.register('immutableheads', pushimmutableheads, listimmutableheads) | 194 for head in repo.stateheads(state): |
195 head = node.hex(head) | |
196 if head in keys: | |
197 keys[head] += ',' + state.name | |
198 else: | |
199 keys[head] = state.name | |
200 return keys | |
201 | |
202 pushkey.register('states-heads', pushstatesheads, liststatesheads) | |
194 | 203 |
195 | 204 |
196 | 205 |
197 | 206 |
198 | 207 |
309 | 318 |
310 def setstate(self, state, nodes): | 319 def setstate(self, state, nodes): |
311 """change state of targets changeset and it's ancestors. | 320 """change state of targets changeset and it's ancestors. |
312 | 321 |
313 Simplify the list of head.""" | 322 Simplify the list of head.""" |
314 assert not isinstance(nodes, basestring) | 323 assert not isinstance(nodes, basestring), repr(nodes) |
315 heads = self._statesheads[state] | 324 heads = self._statesheads[state] |
316 olds = heads[:] | 325 olds = heads[:] |
317 heads.extend(nodes) | 326 heads.extend(nodes) |
318 heads[:] = set(heads) | 327 heads[:] = set(heads) |
319 heads.sort() | 328 heads.sort() |
376 | 385 |
377 ### pull // push support | 386 ### pull // push support |
378 | 387 |
379 def pull(self, remote, *args, **kwargs): | 388 def pull(self, remote, *args, **kwargs): |
380 result = opull(remote, *args, **kwargs) | 389 result = opull(remote, *args, **kwargs) |
381 remoteheads = self._pullimmutableheads(remote) | 390 remoteheads = self._pullstatesheads(remote) |
382 #print [node.short(h) for h in remoteheads] | 391 #print [node.short(h) for h in remoteheads] |
383 self.setstate(ST0, remoteheads) | 392 for st, heads in remoteheads.iteritems(): |
393 self.setstate(st, heads) | |
384 return result | 394 return result |
385 | 395 |
386 def push(self, remote, *args, **opts): | 396 def push(self, remote, *args, **opts): |
387 result = opush(remote, *args, **opts) | 397 result = opush(remote, *args, **opts) |
388 remoteheads = self._pullimmutableheads(remote) | 398 remoteheads = self._pullstatesheads(remote) |
389 self.setstate(ST0, remoteheads) | 399 for st, heads in remoteheads.iteritems(): |
390 if remoteheads != self.stateheads(ST0): | 400 self.setstate(st, heads) |
391 #print 'stuff to push' | 401 if heads != self.stateheads(st): |
392 #print 'remote', [node.short(h) for h in remoteheads] | 402 self._pushstatesheads(remote, st, heads) |
393 #print 'local', [node.short(h) for h in self._statesheads[ST0]] | |
394 self._pushimmutableheads(remote, remoteheads) | |
395 return result | 403 return result |
396 | 404 |
397 def _pushimmutableheads(self, remote, remoteheads): | 405 def _pushstatesheads(self, remote, state, remoteheads): |
398 missing = set(self.stateheads(ST0)) - set(remoteheads) | 406 local = set(self.stateheads(state)) |
407 missing = local - set(remoteheads) | |
399 while missing: | 408 while missing: |
400 h = missing.pop() | 409 h = missing.pop() |
401 try: | 410 try: |
402 remote.pushkey('immutableheads', node.hex(h), '', '1') | 411 remote.pushkey('states-heads', node.hex(h), '', state.name) |
403 except error.RepoLookupError: | 412 except error.RepoLookupError: |
404 missing.update(p.node() for p in repo[h].parents()) | 413 missing.update(p.node() for p in repo[h].parents()) |
405 | 414 |
406 | 415 |
407 def _pullimmutableheads(self, remote): | 416 def _pullstatesheads(self, remote): |
408 self.ui.debug('checking for immutableheadshg on server') | 417 remoteheads = {} |
409 if 'immutableheads' not in remote.listkeys('namespaces'): | 418 self.ui.debug('checking for states-heads on remote server') |
410 self.ui.debug('immutableheads not enabled on the remote server, ' | 419 if 'states-heads' not in remote.listkeys('namespaces'): |
411 'marking everything as frozen') | 420 self.ui.debug('states-heads not enabled on the remote server, ' |
412 remote = remote.heads() | 421 'marking everything as published') |
422 remoteheads[ST0] = remote.heads() | |
413 else: | 423 else: |
414 self.ui.debug('server has immutableheads enabled, merging lists') | 424 self.ui.debug('server has states-heads enabled, merging lists') |
415 remote = map(node.bin, remote.listkeys('immutableheads')) | 425 for hex, statenames in remote.listkeys('states-heads').iteritems(): |
416 return remote | 426 for stn in statenames.split(','): |
427 remoteheads.setdefault(STATESMAP[stn], []).append(node.bin(hex)) | |
428 return remoteheads | |
417 | 429 |
418 ### Tag support | 430 ### Tag support |
419 | 431 |
420 def _tag(self, names, node, *args, **kwargs): | 432 def _tag(self, names, node, *args, **kwargs): |
421 tagnode = o_tag(names, node, *args, **kwargs) | 433 tagnode = o_tag(names, node, *args, **kwargs) |