Changeset - ab89f7ce2c0b
[Not reviewed]
default
0 1 0
Mads Kiilerich - 12 years ago 2013-12-10 19:30:37
madski@unity3d.com
graph: use sets for graph calculations
1 file changed with 8 insertions and 10 deletions:
0 comments (0 inline, 0 general)
kallithea/lib/graphmod.py
Show inline comments
 
@@ -28,25 +28,25 @@ def _first_known_ancestors(parentrev_fun
 
    pending = set([head])
 
    seen = set()
 
    ancestors = set()
 
    minrev = max(nullrev, minrev)
 
    while pending:
 
        r = pending.pop()
 
        if r >= minrev and r not in seen:
 
            if r in knownrevs:
 
                ancestors.add(r)
 
            else:
 
                pending.update(parentrev_func(r))
 
            seen.add(r)
 
    return sorted(ancestors)
 
    return ancestors
 

	
 
def graph_data(repo, revs):
 
    """Return a DAG with colored edge information for revs
 

	
 
    For each DAG node this function emits tuples::
 

	
 
      ((col, color), [(col, nextcol, color)])
 

	
 
    with the following new elements:
 

	
 
      - Tuple (col, color) with column and color index for the current node
 
      - A list of tuples indicating the edges between the current node and its
 
@@ -60,39 +60,37 @@ def _dagwalker(repo, revs):
 
        return
 

	
 
    if repo.alias == 'hg':
 
        parentrev_func = repo._repo.changelog.parentrevs
 
    elif repo.alias == 'git':
 
        def parentrev_func(rev):
 
            return [x.revision for x in repo[rev].parents]
 

	
 
    minrev = min(revs)
 
    knownrevs = set(revs)
 
    acache = {}
 
    for rev in revs:
 
        ctx = repo[rev]
 
        parents = [p.revision for p in ctx.parents]
 
        dagparents = sorted(set(parents) & knownrevs)
 
        mpars = sorted(set(parents) - knownrevs - set([nullrev]))
 
        parents = set(parentrev_func(rev)) - set([nullrev])
 
        dagparents = parents & knownrevs
 
        # Calculate indirect parents
 
        for p in mpars:
 
        for p in parents - dagparents:
 
            ancestors = acache.get(p)
 
            if ancestors is None:
 
                ancestors = acache[p] = _first_known_ancestors(parentrev_func, minrev, revs, p)
 
                ancestors = acache[p] = _first_known_ancestors(parentrev_func, minrev, knownrevs, p)
 
            if ancestors: # some indirect known ancestors found - use them and ignore unknown ancestors
 
                dagparents.extend(g for g in ancestors if g not in dagparents)
 
                dagparents.update(ancestors)
 
            else: # no known ancestors - use the real but unknown parent
 
                dagparents.append(p)
 
                dagparents.add(p)
 

	
 
        yield (ctx.revision, dagparents)
 
        yield (rev, sorted(dagparents))
 

	
 

	
 
def _colored(dag):
 
    """annotates a DAG with colored edge information
 

	
 
    For each DAG node this function emits tuples::
 

	
 
      ((col, color), [(col, nextcol, color)])
 

	
 
    with the following new elements:
 

	
 
      - Tuple (col, color) with column and color index for the current node
0 comments (0 inline, 0 general)