96 by discovery.""" |
97 by discovery.""" |
97 |
98 |
98 def __init__( |
99 def __init__( |
99 self, repo, commonheads=None, ancestorsof=None, missingroots=None |
100 self, repo, commonheads=None, ancestorsof=None, missingroots=None |
100 ): |
101 ): |
101 # at least one of them must not be set |
102 # at most one of them must not be set |
102 assert None in (commonheads, missingroots) |
103 if commonheads is not None and missingroots is not None: |
|
104 m = 'commonheads and missingroots arguments are mutually exclusive' |
|
105 raise error.ProgrammingError(m) |
103 cl = repo.changelog |
106 cl = repo.changelog |
|
107 missing = None |
|
108 common = None |
104 if ancestorsof is None: |
109 if ancestorsof is None: |
105 ancestorsof = cl.heads() |
110 ancestorsof = cl.heads() |
106 if missingroots: |
111 if missingroots: |
107 # TODO remove call to nodesbetween. |
112 # TODO remove call to nodesbetween. |
108 # TODO populate attributes on outgoing instance instead of setting |
113 missing_rev = repo.revs('%ln::%ln', missingroots, ancestorsof) |
109 # discbases. |
114 unfi = repo.unfiltered() |
110 csets, roots, heads = cl.nodesbetween(missingroots, ancestorsof) |
115 ucl = unfi.changelog |
111 included = set(csets) |
116 to_node = ucl.node |
112 discbases = [] |
117 ancestorsof = [to_node(r) for r in ucl.headrevs(missing_rev)] |
113 for n in csets: |
118 parent_revs = ucl.parentrevs |
114 discbases.extend([p for p in cl.parents(n) if p != repo.nullid]) |
119 common_legs = set() |
115 ancestorsof = heads |
120 for r in missing_rev: |
116 commonheads = [n for n in discbases if n not in included] |
121 p1, p2 = parent_revs(r) |
|
122 if p1 not in missing_rev: |
|
123 common_legs.add(p1) |
|
124 if p2 not in missing_rev: |
|
125 common_legs.add(p2) |
|
126 common_legs.discard(nodemod.nullrev) |
|
127 if not common_legs: |
|
128 commonheads = [repo.nullid] |
|
129 common = set() |
|
130 else: |
|
131 commonheads_revs = unfi.revs( |
|
132 'heads(%ld::%ld)', |
|
133 common_legs, |
|
134 common_legs, |
|
135 ) |
|
136 commonheads = [to_node(r) for r in commonheads_revs] |
|
137 common = ucl.ancestors(commonheads_revs, inclusive=True) |
|
138 missing = [to_node(r) for r in missing_rev] |
117 elif not commonheads: |
139 elif not commonheads: |
118 commonheads = [repo.nullid] |
140 commonheads = [repo.nullid] |
119 self.commonheads = commonheads |
141 self.commonheads = commonheads |
120 self.ancestorsof = ancestorsof |
142 self.ancestorsof = ancestorsof |
121 self._revlog = cl |
143 self._revlog = cl |
122 self._common = None |
144 self._common = common |
123 self._missing = None |
145 self._missing = missing |
124 self.excluded = [] |
146 self.excluded = [] |
125 |
147 |
126 def _computecommonmissing(self): |
148 def _computecommonmissing(self): |
127 sets = self._revlog.findcommonmissing( |
149 sets = self._revlog.findcommonmissing( |
128 self.commonheads, self.ancestorsof |
150 self.commonheads, self.ancestorsof |