Changeset - 58fe03c0aad1
[Not reviewed]
default
0 1 0
Mads Kiilerich - 12 years ago 2013-12-10 19:30:37
madski@unity3d.com
graph: cleanup of graph data - remove redundant data
1 file changed with 11 insertions and 23 deletions:
0 comments (0 inline, 0 general)
kallithea/lib/graphmod.py
Show inline comments
 
@@ -43,82 +43,78 @@ 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
 
        parents.
 
    """
 
    dag = _dagwalker(repo, revs, repo.alias)
 
    return [(vtx, edges) for (_id, _type, ctx, vtx, edges) in _colored(dag)]
 
    dag = _dagwalker(repo, revs)
 
    return list(_colored(dag))
 

	
 
def _dagwalker(repo, revs, alias):
 
def _dagwalker(repo, revs):
 
    if not revs:
 
        return
 

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

	
 
    lowestrev = min(revs)
 
    gpcache = {}
 

	
 
    knownrevs = set(revs)
 
    for rev in revs:
 
        ctx = repo[rev]
 
        parents = sorted(set([p.revision for p in ctx.parents
 
                              if p.revision in knownrevs]))
 
        mpars = [p.revision for p in ctx.parents if
 
                 p.revision != nullrev and p.revision not in parents]
 

	
 
        for mpar in mpars:
 
            gp = gpcache.get(mpar)
 
            if gp is None:
 
                gp = gpcache[mpar] = grandparent(cl, lowestrev, revs, mpar)
 
            if not gp:
 
                parents.append(mpar)
 
            else:
 
                parents.extend(g for g in gp if g not in parents)
 

	
 
        yield (ctx.revision, 'C', ctx, parents)
 
        yield (ctx.revision, parents)
 

	
 

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

	
 
    For each DAG node this function emits tuples::
 

	
 
      (id, type, data, (col, color), [(col, nextcol, color)])
 
      ((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
 
        parents.
 
    """
 
    seen = []
 
    colors = {}
 
    newcolor = 1
 

	
 
    getconf = lambda rev: {}
 

	
 
    for (cur, type, data, parents) in dag:
 
    for (cur, parents) in dag:
 

	
 
        # Compute seen and next
 
        if cur not in seen:
 
            seen.append(cur)  # new head
 
            colors[cur] = newcolor
 
            newcolor += 1
 

	
 
        col = seen.index(cur)
 
        color = colors.pop(cur)
 
        next = seen[:]
 

	
 
        # Add parents to next
 
@@ -128,28 +124,20 @@ def _colored(dag):
 
        # Set colors for the parents
 
        for i, p in enumerate(addparents):
 
            if not i:
 
                colors[p] = color
 
            else:
 
                colors[p] = newcolor
 
                newcolor += 1
 

	
 
        # Add edges to the graph
 
        edges = []
 
        for ecol, eid in enumerate(seen):
 
            if eid in next:
 
                bconf = getconf(eid)
 
                edges.append((
 
                    ecol, next.index(eid), colors[eid],
 
                    bconf.get('width', -1),
 
                    bconf.get('color', '')))
 
                edges.append((ecol, next.index(eid), colors[eid]))
 
            elif eid == cur:
 
                for p in parents:
 
                    bconf = getconf(p)
 
                    edges.append((
 
                        ecol, next.index(p), colors[p] if len(parents) > 1 else color,
 
                        bconf.get('width', -1),
 
                        bconf.get('color', '')))
 
                    edges.append((ecol, next.index(p), colors[p] if len(parents) > 1 else color))
 

	
 
        # Yield and move on
 
        yield (cur, type, data, (col, color), edges)
 
        yield ((col, color), edges)
 
        seen = next
0 comments (0 inline, 0 general)