373 - It's next state. |
373 - It's next state. |
374 |
374 |
375 XXX maybe we could stick description of the state semantic here. |
375 XXX maybe we could stick description of the state semantic here. |
376 """ |
376 """ |
377 |
377 |
|
378 # plumbery utily |
378 def __init__(self, name, properties=0, next=None): |
379 def __init__(self, name, properties=0, next=None): |
379 self.name = name |
380 self.name = name |
380 self.properties = properties |
381 self.properties = properties |
381 assert next is None or self < next |
382 assert next is None or self < next |
382 self.next = next |
383 self.next = next |
383 |
|
384 def __repr__(self): |
|
385 return 'state(%s)' % self.name |
|
386 |
|
387 def __str__(self): |
|
388 return self.name |
|
389 |
|
390 @util.propertycache |
384 @util.propertycache |
391 def trackheads(self): |
385 def trackheads(self): |
392 """Do we need to track heads of changeset in this state ? |
386 """Do we need to track heads of changeset in this state ? |
393 |
387 |
394 We don't need to track heads for the last state as this is repo heads""" |
388 We don't need to track heads for the last state as this is repo heads""" |
395 return self.next is not None |
389 return self.next is not None |
396 |
390 |
|
391 # public utility |
397 def __cmp__(self, other): |
392 def __cmp__(self, other): |
398 """Use property to compare states. |
393 """Use property to compare states. |
399 |
394 |
400 This is a naiv approach that assume the the next state are strictly |
395 This is a naiv approach that assume the the next state are strictly |
401 more property than the one before |
396 more property than the one before |
402 # assert min(self, other).properties = self.properties & other.properties |
397 # assert min(self, other).properties = self.properties & other.properties |
403 """ |
398 """ |
404 return cmp(self.properties, other.properties) |
399 return cmp(self.properties, other.properties) |
405 |
400 |
|
401 @util.propertycache |
|
402 def mutable(self): |
|
403 return bool(self.properties & _MUTABLE) |
|
404 |
|
405 # display code |
|
406 def __repr__(self): |
|
407 return 'state(%s)' % self.name |
|
408 |
|
409 def __str__(self): |
|
410 return self.name |
|
411 |
|
412 |
|
413 # revset utility |
406 @util.propertycache |
414 @util.propertycache |
407 def _revsetheads(self): |
415 def _revsetheads(self): |
408 """function to be used by revset to finds heads of this states""" |
416 """function to be used by revset to finds heads of this states""" |
409 assert self.trackheads |
417 assert self.trackheads |
410 def revsetheads(repo, subset, x): |
418 def revsetheads(repo, subset, x): |
653 # rebase.nullmerge is issued in the detach case |
661 # rebase.nullmerge is issued in the detach case |
654 rebase = extensions.find('rebase') |
662 rebase = extensions.find('rebase') |
655 rebased = [rev for rev, rbst in result[2].items() if rbst != rebase.nullmerge] |
663 rebased = [rev for rev, rbst in result[2].items() if rbst != rebase.nullmerge] |
656 base = repo.changelog.node(min(rebased)) |
664 base = repo.changelog.node(min(rebased)) |
657 state = repo.nodestate(base) |
665 state = repo.nodestate(base) |
658 if not state.properties & _MUTABLE: |
666 if not state.mutable: |
659 raise util.Abort(_('can not rebase published changeset %s') |
667 raise util.Abort(_('can not rebase published changeset %s') |
660 % node.short(base), |
668 % node.short(base), |
661 hint=_('see `hg help --extension states` for details')) |
669 hint=_('see `hg help --extension states` for details')) |
662 return result |
670 return result |
663 |
671 |
665 if 'rev' in kwargs: |
673 if 'rev' in kwargs: |
666 # we can take the min as non linear import wil break |
674 # we can take the min as non linear import wil break |
667 base = min(scmutil.revrange(repo, kwargs['rev'])) |
675 base = min(scmutil.revrange(repo, kwargs['rev'])) |
668 basenode = repo.changelog.node(base) |
676 basenode = repo.changelog.node(base) |
669 state = repo.nodestate(basenode) |
677 state = repo.nodestate(basenode) |
670 if not state.properties & _MUTABLE: |
678 if not state.mutable: |
671 raise util.Abort(_('can not qimport published changeset %s') |
679 raise util.Abort(_('can not qimport published changeset %s') |
672 % node.short(basenode), |
680 % node.short(basenode), |
673 hint=_('see `hg help --extension states` for details')) |
681 hint=_('see `hg help --extension states` for details')) |
674 return orig(queue, repo, *args, **kwargs) |
682 return orig(queue, repo, *args, **kwargs) |
675 |
683 |