20 context.basectx.orphan = context.basectx.unstable |
20 context.basectx.orphan = context.basectx.unstable |
21 |
21 |
22 if not util.safehasattr(context.basectx, 'isunstable'): |
22 if not util.safehasattr(context.basectx, 'isunstable'): |
23 context.basectx.isunstable = context.basectx.troubled |
23 context.basectx.isunstable = context.basectx.troubled |
24 |
24 |
|
25 class stack(object): |
|
26 """object represent a stack and common logic associated to it.""" |
|
27 |
|
28 def __init__(self, repo, branch=None, topic=None): |
|
29 self._repo = repo |
|
30 self.branch = branch |
|
31 self.topic = topic |
|
32 if topic is not None and branch is not None: |
|
33 raise error.ProgrammingError('both branch and topic specified (not defined yet)') |
|
34 elif topic is not None: |
|
35 trevs = repo.revs("topic(%s) - obsolete()", topic) |
|
36 elif branch is not None: |
|
37 trevs = repo.revs("branch(%s) - public() - obsolete() - topic()", branch) |
|
38 else: |
|
39 raise error.ProgrammingError('neither branch and topic specified (not defined yet)') |
|
40 self._revs = trevs |
|
41 |
|
42 def __iter__(self): |
|
43 return iter(self.revs) |
|
44 |
|
45 def __getitem__(self, index): |
|
46 return self.revs[index] |
|
47 |
|
48 def index(self, item): |
|
49 return self.revs.index(item) |
|
50 |
|
51 @util.propertycache |
|
52 def revs(self): |
|
53 revs = _orderrevs(self._repo, self._revs) |
|
54 if revs: |
|
55 pt1 = self._repo[revs[0]].p1() |
|
56 if pt1.obsolete(): |
|
57 pt1 = self._repo[_singlesuccessor(self._repo, pt1)] |
|
58 revs.insert(0, pt1.rev()) |
|
59 return revs |
|
60 |
25 def getstack(repo, branch=None, topic=None): |
61 def getstack(repo, branch=None, topic=None): |
26 # XXX need sorting |
62 # XXX need sorting |
27 if topic is not None and branch is not None: |
63 return stack(repo, branch=branch, topic = topic) |
28 raise error.ProgrammingError('both branch and topic specified (not defined yet)') |
|
29 elif topic is not None: |
|
30 trevs = repo.revs("topic(%s) - obsolete()", topic) |
|
31 elif branch is not None: |
|
32 trevs = repo.revs("branch(%s) - public() - obsolete() - topic()", branch) |
|
33 else: |
|
34 raise error.ProgrammingError('neither branch and topic specified (not defined yet)') |
|
35 revs = _orderrevs(repo, trevs) |
|
36 if revs: |
|
37 pt1 = repo[revs[0]].p1() |
|
38 if pt1.obsolete(): |
|
39 pt1 = repo[_singlesuccessor(repo, pt1)] |
|
40 revs.insert(0, pt1.rev()) |
|
41 return revs |
|
42 |
64 |
43 def labelsgen(prefix, labelssuffix): |
65 def labelsgen(prefix, labelssuffix): |
44 """ Takes a label prefix and a list of suffixes. Returns a string of the prefix |
66 """ Takes a label prefix and a list of suffixes. Returns a string of the prefix |
45 formatted with each suffix separated with a space. |
67 formatted with each suffix separated with a space. |
46 """ |
68 """ |