states.py
changeset 19 8784a989a572
parent 18 9ffe946febc0
child 20 9983f240ac63
equal deleted inserted replaced
18:9ffe946febc0 19:8784a989a572
    35 _NOSHARE=2
    35 _NOSHARE=2
    36 _MUTABLE=1
    36 _MUTABLE=1
    37 
    37 
    38 class state(object):
    38 class state(object):
    39 
    39 
    40     def __init__(self, name, order=0, next=None):
    40     def __init__(self, name, properties=0, next=None):
    41         self.name = name
    41         self.name = name
    42         self.order = order
    42         self.properties = properties
    43         assert next is None or self < next
    43         assert next is None or self < next
    44         self.next = next
    44         self.next = next
    45 
    45 
    46     def __repr__(self):
    46     def __repr__(self):
    47         return 'state(%s)' % self.name
    47         return 'state(%s)' % self.name
    55 
    55 
    56         We don't need to track heads for the last state as this is repos heads"""
    56         We don't need to track heads for the last state as this is repos heads"""
    57         return self.next is not None
    57         return self.next is not None
    58 
    58 
    59     def __cmp__(self, other):
    59     def __cmp__(self, other):
    60         return cmp(self.order, other.order)
    60         return cmp(self.properties, other.properties)
    61 
    61 
    62     @util.propertycache
    62     @util.propertycache
    63     def _revsetheads(self):
    63     def _revsetheads(self):
    64         """function to be used by revset to finds heads of this states"""
    64         """function to be used by revset to finds heads of this states"""
    65         assert self.trackheads
    65         assert self.trackheads
    82 ST1 = state('ready', _MUTABLE, next=ST2)
    82 ST1 = state('ready', _MUTABLE, next=ST2)
    83 ST0 = state('published', next=ST1)
    83 ST0 = state('published', next=ST1)
    84 
    84 
    85 STATES = (ST0, ST1, ST2)
    85 STATES = (ST0, ST1, ST2)
    86 
    86 
       
    87 def laststatewithout(prop):
       
    88     for state in STATES:
       
    89         if not state.properties & prop:
       
    90             candidate = state
       
    91         else:
       
    92             return candidate
       
    93 
    87 # util function
    94 # util function
    88 #############################
    95 #############################
    89 def noderange(repo, revsets):
    96 def noderange(repo, revsets):
    90     return map(repo.changelog.node,
    97     return map(repo.changelog.node,
    91                scmutil.revrange(repo, revsets))
    98                scmutil.revrange(repo, revsets))
   139     extensions.wrapfunction(discovery, 'findcommonincoming', filterprivatein)
   146     extensions.wrapfunction(discovery, 'findcommonincoming', filterprivatein)
   140 
   147 
   141     # Write protocols
   148     # Write protocols
   142     ####################
   149     ####################
   143     def heads(repo, proto):
   150     def heads(repo, proto):
   144         h = repo.stateheads(ST1)
   151         st = laststatewithout(_NOSHARE)
       
   152         h = repo.stateheads(st)
   145         return wireproto.encodelist(h) + "\n"
   153         return wireproto.encodelist(h) + "\n"
   146 
   154 
   147     def _reducehead(wirerepo, heads):
   155     def _reducehead(wirerepo, heads):
   148         """heads filtering is done repo side"""
   156         """heads filtering is done repo side"""
   149         return heads
   157         return heads
   242             if state.next is not None and state.next.trackheads:
   250             if state.next is not None and state.next.trackheads:
   243                 self.setstate(state.next, nodes) # cascading
   251                 self.setstate(state.next, nodes) # cascading
   244 
   252 
   245         def _reducehead(self, candidates):
   253         def _reducehead(self, candidates):
   246             selected = set()
   254             selected = set()
       
   255             st = laststatewithout(_NOSHARE)
   247             for candidate in candidates:
   256             for candidate in candidates:
   248                 rev = self.changelog.rev(candidate)
   257                 rev = self.changelog.rev(candidate)
   249                 ok = True
   258                 ok = True
   250                 for h in self.stateheads(ST1):
   259                 for h in self.stateheads(st):
   251                     revh = self.changelog.rev(h)
   260                     revh = self.changelog.rev(h)
   252                     if self.changelog.descendant(revh, rev):
   261                     if self.changelog.descendant(revh, rev):
   253                         ok = False
   262                         ok = False
   254                         selected.add(h)
   263                         selected.add(h)
   255                 if ok:
   264                 if ok:
   256                     selected.add(candidate)
   265                     selected.add(candidate)
   257             return sorted(selected)
   266             return sorted(selected)
   258 
   267 
   259         def cancopy(self):
   268         def cancopy(self):
   260             return o_cancopy() and (self.stateheads(ST1) == self.heads())
   269             st = laststatewithout(_NOSHARE)
       
   270             return o_cancopy() and (self.stateheads(st) == self.heads())
   261 
   271 
   262     repo.__class__ = statefulrepo
   272     repo.__class__ = statefulrepo
   263 
   273