author | Jun Wu <quark@fb.com> |
Sat, 24 Jun 2017 21:13:48 -0700 | |
changeset 33056 | 2312e70cf78b |
parent 32879 | 1858fc2327ef |
child 33142 | 4f49810a1011 |
permissions | -rw-r--r-- |
32879
1858fc2327ef
template: add predecessors template
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1 |
# obsutil.py - utility functions for obsolescence |
1858fc2327ef
template: add predecessors template
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2 |
# |
1858fc2327ef
template: add predecessors template
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3 |
# Copyright 2017 Boris Feld <boris.feld@octobus.net> |
1858fc2327ef
template: add predecessors template
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
4 |
# |
1858fc2327ef
template: add predecessors template
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
5 |
# This software may be used and distributed according to the terms of the |
1858fc2327ef
template: add predecessors template
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
6 |
# GNU General Public License version 2 or any later version. |
1858fc2327ef
template: add predecessors template
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
7 |
|
1858fc2327ef
template: add predecessors template
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
8 |
from __future__ import absolute_import |
1858fc2327ef
template: add predecessors template
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
9 |
|
1858fc2327ef
template: add predecessors template
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
10 |
def closestpredecessors(repo, nodeid): |
1858fc2327ef
template: add predecessors template
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
11 |
"""yield the list of next predecessors pointing on visible changectx nodes |
1858fc2327ef
template: add predecessors template
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
12 |
|
1858fc2327ef
template: add predecessors template
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
13 |
This function respect the repoview filtering, filtered revision will be |
1858fc2327ef
template: add predecessors template
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
14 |
considered missing. |
1858fc2327ef
template: add predecessors template
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
15 |
""" |
1858fc2327ef
template: add predecessors template
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
16 |
|
1858fc2327ef
template: add predecessors template
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
17 |
precursors = repo.obsstore.precursors |
1858fc2327ef
template: add predecessors template
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
18 |
stack = [nodeid] |
1858fc2327ef
template: add predecessors template
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
19 |
seen = set(stack) |
1858fc2327ef
template: add predecessors template
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
20 |
|
1858fc2327ef
template: add predecessors template
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
21 |
while stack: |
1858fc2327ef
template: add predecessors template
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
22 |
current = stack.pop() |
1858fc2327ef
template: add predecessors template
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
23 |
currentpreccs = precursors.get(current, ()) |
1858fc2327ef
template: add predecessors template
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
24 |
|
1858fc2327ef
template: add predecessors template
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
25 |
for prec in currentpreccs: |
1858fc2327ef
template: add predecessors template
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
26 |
precnodeid = prec[0] |
1858fc2327ef
template: add predecessors template
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
27 |
|
1858fc2327ef
template: add predecessors template
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
28 |
# Basic cycle protection |
1858fc2327ef
template: add predecessors template
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
29 |
if precnodeid in seen: |
1858fc2327ef
template: add predecessors template
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
30 |
continue |
1858fc2327ef
template: add predecessors template
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
31 |
seen.add(precnodeid) |
1858fc2327ef
template: add predecessors template
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
32 |
|
1858fc2327ef
template: add predecessors template
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
33 |
if precnodeid in repo: |
1858fc2327ef
template: add predecessors template
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
34 |
yield precnodeid |
1858fc2327ef
template: add predecessors template
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
35 |
else: |
1858fc2327ef
template: add predecessors template
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
36 |
stack.append(precnodeid) |