Changeset - 05a85a6cecba
[Not reviewed]
default
0 2 0
Mads Kiilerich - 10 years ago 2016-02-22 21:07:47
madski@unity3d.com
graph: detect git branches and colourise them properly without rainbow effect (Issue #188)

This is based on research and patches by Andrew Shadura.

When using Git, only commits pointed to by branch references have their
branches set. In general, there's no way in Git to find out which branch
a commit belongs to, so we can try to deduce that from the merge topology.

In other words, if we know the branch name, we know it's a different colour
than any different branch. If we don't (it is None), we guesstimate the first
parent is probably on the same branch. The relevant part of the code before
2da0dc09 used a similar, yet simpler, algorithm.
2 files changed with 2 insertions and 2 deletions:
0 comments (0 inline, 0 general)
kallithea/lib/graphmod.py
Show inline comments
 
@@ -125,46 +125,46 @@ def _colored(repo, dag):
 
            newcolor += 1
 

	
 
        col = row.index(rev)
 
        addparents = [p for p in dagparents if p not in row]
 

	
 
        # Add unknown parents to nextrow
 
        tmprow = row[:]
 
        tmprow[col:col + 1] = reversed(addparents) # highest revs first (to the right), dead ends last (to the left)
 
        # Filter old fake parents but keep new ones
 
        nextrow = []
 
        for r in tmprow:
 
            if r >= 0 or r in dagparents:
 
                nextrow.append(r)
 
            else:
 
                colors.pop(r)
 
                obs.pop(r)
 

	
 
        # Let color and obs for this rev be "inherited" by the first "parent"
 
        color = colors.pop(rev)
 
        if addparents:
 
            b = branch(rev)
 
            searching = True
 
            for p in reversed(addparents):
 
                obs[p] = int(repo[p].obsolete)
 
                if searching and branch(abs(p)) == b:
 
                if searching and branch(abs(p)) in [b, None]:
 
                    # This is the first parent on the same branch - inherit the color
 
                    colors[p] = color
 
                    searching = False # make sure we don't give the color away twice
 
                else:
 
                    colors[p] = newcolor
 
                    newcolor += 1
 

	
 
        # Add edges to the graph
 
        edges = []
 
        for ecol, ep in enumerate(row):
 
            if ep in nextrow:
 
                edges.append((ecol, nextrow.index(ep), colors[ep], obs[ep]))
 
            elif ep == rev:
 
                for p in dagparents:
 
                    edges.append((ecol, nextrow.index(p), colors[p], obs[p]))
 

	
 
        # Yield and move on
 
        closing = int(repo[rev].closesbranch)
 
        obsolete = int(repo[rev].obsolete)
 
        yield ((col, color), edges, closing, obsolete)
 
        row = nextrow
kallithea/tests/functional/test_changelog.py
Show inline comments
 
@@ -49,49 +49,49 @@ class TestChangelogController(TestContro
 

	
 
        response.mustcontain(
 
            """<span class="changeset_hash">r539:22baf968d547</span>"""
 
        )
 

	
 
    def test_index_git(self):
 
        self.log_user()
 
        response = self.app.get(url(controller='changelog', action='index',
 
                                    repo_name=GIT_REPO))
 

	
 
        response.mustcontain('''id="chg_20" class="container "''') # why no mergerow for git?
 
        response.mustcontain(
 
            """<input class="changeset_range" """
 
            """id="95f9a91d775b0084b2368ae7779e44931c849c0e" """
 
            """name="95f9a91d775b0084b2368ae7779e44931c849c0e" """
 
            """type="checkbox" value="1" />"""
 
        )
 

	
 
        response.mustcontain(
 
            """<span class="changeset_hash">r613:95f9a91d775b</span>"""
 
        )
 

	
 
        response.mustcontain("""fixing stupid typo in context for mercurial""")
 

	
 
        response.mustcontain("""var jsdata = [[[0, 1], [[0, 0, 2, 0]], 0, 0], [[0, 2], [[0, 0, 2, 0]], 0, 0], [[0, 2], [[0, 0, 2, 0]], 0, 0], [[0, 2], [[0, 0, 2, 0]], 0, 0], [[0, 2], [[0, 0, 2, 0]], 0, 0], [[0, 2], [[0, 0, 2, 0]], 0, 0], [[0, 2], [[0, 0, 2, 0]], 0, 0], [[0, 2], [[0, 0, 2, 0]], 0, 0], [[0, 2], [[0, 1, 3, 0], [0, 0, 2, 0]], 0, 0], [[0, 2], [[0, 0, 2, 0], [1, 1, 3, 0]], 0, 0], [[0, 2], [[0, 0, 3, 0], [1, 0, 3, 0]], 0, 0], [[0, 3], [[0, 1, 4, 0], [0, 0, 3, 0]], 0, 0], [[0, 3], [[0, 0, 3, 0], [1, 1, 4, 0]], 0, 0], [[0, 3], [[0, 0, 3, 0], [1, 1, 4, 0]], 0, 0], [[1, 4], [[0, 0, 3, 0], [1, 0, 3, 0]], 0, 0], [[0, 3], [[0, 1, 5, 0], [0, 0, 3, 0]], 0, 0], [[0, 3], [[0, 0, 3, 0], [1, 1, 5, 0]], 0, 0], [[0, 3], [[0, 0, 3, 0], [1, 1, 5, 0]], 0, 0], [[0, 3], [[0, 0, 3, 0], [1, 1, 5, 0]], 0, 0], [[0, 3], [[0, 0, 3, 0], [1, 1, 5, 0]], 0, 0], [[0, 3], [[0, 0, 3, 0], [1, 1, 5, 0]], 0, 0], [[0, 3], [[0, 0, 3, 0], [1, 1, 5, 0]], 0, 0], [[1, 5], [[0, 0, 3, 0], [1, 1, 5, 0]], 0, 0], [[1, 5], [[0, 0, 3, 0], [1, 1, 5, 0], [1, 0, 3, 0]], 0, 0], [[0, 3], [[0, 0, 3, 0], [1, 1, 5, 0]], 0, 0], [[1, 5], [[0, 0, 3, 0], [1, 1, 5, 0]], 0, 0], [[1, 5], [[0, 0, 3, 0], [1, 1, 5, 0]], 0, 0], [[1, 5], [[0, 0, 3, 0], [1, 1, 5, 0]], 0, 0], [[1, 5], [[0, 0, 3, 0], [1, 0, 3, 0], [1, 1, 5, 0]], 0, 0], [[1, 5], [[0, 0, 3, 0], [1, 1, 5, 0]], 0, 0], [[1, 5], [[0, 0, 3, 0], [1, 1, 5, 0]], 0, 0], [[0, 3], [[0, 0, 5, 0], [1, 0, 5, 0]], 0, 0], [[0, 5], [[0, 0, 5, 0]], 0, 0], [[0, 5], [[0, 0, 5, 0]], 0, 0], [[0, 5], [[0, 0, 5, 0]], 0, 0], [[0, 5], [[0, 0, 5, 0]], 0, 0], [[0, 5], [[0, 0, 5, 0]], 0, 0], [[0, 5], [[0, 1, 6, 0], [0, 0, 5, 0]], 0, 0], [[0, 5], [[0, 0, 5, 0], [1, 1, 6, 0]], 0, 0], [[1, 6], [[0, 0, 5, 0], [1, 1, 6, 0]], 0, 0], [[1, 6], [[0, 0, 5, 0], [1, 0, 5, 0]], 0, 0], [[0, 5], [[0, 0, 5, 0]], 0, 0], [[0, 5], [[0, 1, 7, 0], [0, 0, 5, 0]], 0, 0], [[0, 5], [[0, 0, 5, 0], [1, 1, 7, 0]], 0, 0], [[1, 7], [[0, 0, 5, 0], [1, 1, 7, 0]], 0, 0], [[1, 7], [[0, 0, 5, 0], [1, 1, 7, 0], [1, 0, 5, 0]], 0, 0], [[0, 5], [[0, 0, 5, 0], [1, 1, 7, 0]], 0, 0], [[1, 7], [[0, 0, 5, 0], [1, 0, 5, 0]], 0, 0], [[0, 5], [[0, 1, 8, 0], [0, 0, 5, 0]], 0, 0], [[0, 5], [[0, 0, 5, 0], [1, 1, 8, 0]], 0, 0], [[1, 8], [[0, 0, 5, 0], [1, 0, 5, 0]], 0, 0], [[0, 5], [[0, 0, 5, 0]], 0, 0], [[0, 5], [[0, 0, 5, 0]], 0, 0], [[0, 5], [[0, 0, 5, 0]], 0, 0], [[0, 5], [[0, 1, 9, 0], [0, 0, 5, 0]], 0, 0], [[0, 5], [[0, 0, 5, 0], [1, 1, 9, 0]], 0, 0], [[1, 9], [[0, 0, 5, 0], [1, 0, 5, 0]], 0, 0], [[0, 5], [[0, 0, 5, 0]], 0, 0], [[0, 5], [[0, 0, 5, 0]], 0, 0], [[0, 5], [[0, 0, 5, 0]], 0, 0], [[0, 5], [[0, 1, 10, 0], [0, 0, 5, 0]], 0, 0], [[0, 5], [[0, 0, 5, 0], [1, 1, 10, 0]], 0, 0], [[1, 10], [[0, 0, 5, 0], [1, 0, 5, 0], [1, 1, 10, 0]], 0, 0], [[1, 10], [[0, 0, 5, 0], [1, 1, 10, 0]], 0, 0], [[0, 5], [[0, 0, 5, 0], [1, 1, 10, 0]], 0, 0], [[0, 5], [[0, 0, 5, 0], [1, 1, 10, 0]], 0, 0], [[0, 5], [[0, 0, 5, 0], [1, 1, 10, 0]], 0, 0], [[0, 5], [[0, 0, 5, 0], [1, 1, 10, 0]], 0, 0], [[0, 5], [[0, 0, 5, 0], [1, 1, 10, 0]], 0, 0], [[0, 5], [[0, 0, 5, 0], [1, 1, 10, 0]], 0, 0], [[0, 5], [[0, 0, 10, 0], [1, 0, 10, 0]], 0, 0], [[0, 10], [[0, 0, 10, 0]], 0, 0], [[0, 10], [[0, 0, 10, 0]], 0, 0], [[0, 10], [[0, 0, 10, 0]], 0, 0], [[0, 10], [[0, 1, 11, 0], [0, 0, 10, 0]], 0, 0], [[0, 10], [[0, 1, 12, 0], [0, 0, 10, 0], [1, 2, 11, 0]], 0, 0], [[2, 11], [[0, 0, 10, 0], [1, 1, 12, 0], [2, 0, 10, 0]], 0, 0], [[0, 10], [[0, 0, 10, 0], [1, 1, 12, 0]], 0, 0], [[0, 10], [[0, 0, 10, 0], [1, 1, 12, 0]], 0, 0], [[0, 10], [[0, 0, 10, 0], [1, 1, 12, 0]], 0, 0], [[1, 12], [[0, 0, 10, 0], [1, 0, 10, 0], [1, 1, 12, 0]], 0, 0], [[1, 12], [[0, 0, 10, 0], [1, 1, 12, 0]], 0, 0], [[0, 10], [[0, 0, 10, 0], [1, 1, 12, 0]], 0, 0], [[0, 10], [[0, 0, 10, 0], [1, 1, 12, 0]], 0, 0], [[0, 10], [[0, 0, 10, 0], [1, 1, 12, 0]], 0, 0], [[0, 10], [[0, 0, 10, 0], [1, 1, 12, 0]], 0, 0], [[0, 10], [[0, 1, 12, 0], [0, 0, 10, 0], [1, 1, 12, 0]], 0, 0], [[0, 10], [[0, 0, 10, 0], [1, 1, 12, 0]], 0, 0], [[1, 12], [[0, 0, 10, 0], [1, 0, 10, 0]], 0, 0], [[0, 10], [[0, 0, 10, 0]], 0, 0], [[0, 10], [[0, 0, 10, 0]], 0, 0], [[0, 10], [[0, 0, 10, 0]], 0, 0], [[0, 10], [[0, 0, 10, 0]], 0, 0], [[0, 10], [[0, 0, 10, 0]], 0, 0], [[0, 10], [[0, 0, 10, 0]], 0, 0], [[0, 10], [[0, 0, 10, 0]], 0, 0], [[0, 10], [[0, 0, 10, 0]], 0, 0], [[0, 10], [[0, 0, 10, 0]], 0, 0], [[0, 10], [[0, 0, 10, 0]], 0, 0], [[0, 10], [[0, 0, 10, 0]], 0, 0]];""")
 
        response.mustcontain("""var jsdata = [[[0, 1], [[0, 0, 1, 0]], 0, 0], [[0, 1], [[0, 0, 1, 0]], 0, 0], [[0, 1], [[0, 0, 1, 0]], 0, 0], [[0, 1], [[0, 0, 1, 0]], 0, 0], [[0, 1], [[0, 0, 1, 0]], 0, 0], [[0, 1], [[0, 0, 1, 0]], 0, 0], [[0, 1], [[0, 0, 1, 0]], 0, 0], [[0, 1], [[0, 0, 1, 0]], 0, 0], [[0, 1], [[0, 1, 2, 0], [0, 0, 1, 0]], 0, 0], [[0, 1], [[0, 0, 1, 0], [1, 1, 2, 0]], 0, 0], [[0, 1], [[0, 0, 2, 0], [1, 0, 2, 0]], 0, 0], [[0, 2], [[0, 1, 3, 0], [0, 0, 2, 0]], 0, 0], [[0, 2], [[0, 0, 2, 0], [1, 1, 3, 0]], 0, 0], [[0, 2], [[0, 0, 2, 0], [1, 1, 3, 0]], 0, 0], [[1, 3], [[0, 0, 2, 0], [1, 0, 2, 0]], 0, 0], [[0, 2], [[0, 1, 4, 0], [0, 0, 2, 0]], 0, 0], [[0, 2], [[0, 0, 2, 0], [1, 1, 4, 0]], 0, 0], [[0, 2], [[0, 0, 2, 0], [1, 1, 4, 0]], 0, 0], [[0, 2], [[0, 0, 2, 0], [1, 1, 4, 0]], 0, 0], [[0, 2], [[0, 0, 2, 0], [1, 1, 4, 0]], 0, 0], [[0, 2], [[0, 0, 2, 0], [1, 1, 4, 0]], 0, 0], [[0, 2], [[0, 0, 2, 0], [1, 1, 4, 0]], 0, 0], [[1, 4], [[0, 0, 2, 0], [1, 1, 4, 0]], 0, 0], [[1, 4], [[0, 0, 2, 0], [1, 1, 4, 0], [1, 0, 2, 0]], 0, 0], [[0, 2], [[0, 0, 2, 0], [1, 1, 4, 0]], 0, 0], [[1, 4], [[0, 0, 2, 0], [1, 1, 4, 0]], 0, 0], [[1, 4], [[0, 0, 2, 0], [1, 1, 4, 0]], 0, 0], [[1, 4], [[0, 0, 2, 0], [1, 1, 4, 0]], 0, 0], [[1, 4], [[0, 0, 2, 0], [1, 0, 2, 0], [1, 1, 4, 0]], 0, 0], [[1, 4], [[0, 0, 2, 0], [1, 1, 4, 0]], 0, 0], [[1, 4], [[0, 0, 2, 0], [1, 1, 4, 0]], 0, 0], [[0, 2], [[0, 0, 4, 0], [1, 0, 4, 0]], 0, 0], [[0, 4], [[0, 0, 4, 0]], 0, 0], [[0, 4], [[0, 0, 4, 0]], 0, 0], [[0, 4], [[0, 0, 4, 0]], 0, 0], [[0, 4], [[0, 0, 4, 0]], 0, 0], [[0, 4], [[0, 0, 4, 0]], 0, 0], [[0, 4], [[0, 1, 5, 0], [0, 0, 4, 0]], 0, 0], [[0, 4], [[0, 0, 4, 0], [1, 1, 5, 0]], 0, 0], [[1, 5], [[0, 0, 4, 0], [1, 1, 5, 0]], 0, 0], [[1, 5], [[0, 0, 4, 0], [1, 0, 4, 0]], 0, 0], [[0, 4], [[0, 0, 4, 0]], 0, 0], [[0, 4], [[0, 1, 6, 0], [0, 0, 4, 0]], 0, 0], [[0, 4], [[0, 0, 4, 0], [1, 1, 6, 0]], 0, 0], [[1, 6], [[0, 0, 4, 0], [1, 1, 6, 0]], 0, 0], [[1, 6], [[0, 0, 4, 0], [1, 1, 6, 0], [1, 0, 4, 0]], 0, 0], [[0, 4], [[0, 0, 4, 0], [1, 1, 6, 0]], 0, 0], [[1, 6], [[0, 0, 4, 0], [1, 0, 4, 0]], 0, 0], [[0, 4], [[0, 1, 7, 0], [0, 0, 4, 0]], 0, 0], [[0, 4], [[0, 0, 4, 0], [1, 1, 7, 0]], 0, 0], [[1, 7], [[0, 0, 4, 0], [1, 0, 4, 0]], 0, 0], [[0, 4], [[0, 0, 4, 0]], 0, 0], [[0, 4], [[0, 0, 4, 0]], 0, 0], [[0, 4], [[0, 0, 4, 0]], 0, 0], [[0, 4], [[0, 1, 8, 0], [0, 0, 4, 0]], 0, 0], [[0, 4], [[0, 0, 4, 0], [1, 1, 8, 0]], 0, 0], [[1, 8], [[0, 0, 4, 0], [1, 0, 4, 0]], 0, 0], [[0, 4], [[0, 0, 4, 0]], 0, 0], [[0, 4], [[0, 0, 4, 0]], 0, 0], [[0, 4], [[0, 0, 4, 0]], 0, 0], [[0, 4], [[0, 1, 9, 0], [0, 0, 4, 0]], 0, 0], [[0, 4], [[0, 0, 4, 0], [1, 1, 9, 0]], 0, 0], [[1, 9], [[0, 0, 4, 0], [1, 0, 4, 0], [1, 1, 9, 0]], 0, 0], [[1, 9], [[0, 0, 4, 0], [1, 1, 9, 0]], 0, 0], [[0, 4], [[0, 0, 4, 0], [1, 1, 9, 0]], 0, 0], [[0, 4], [[0, 0, 4, 0], [1, 1, 9, 0]], 0, 0], [[0, 4], [[0, 0, 4, 0], [1, 1, 9, 0]], 0, 0], [[0, 4], [[0, 0, 4, 0], [1, 1, 9, 0]], 0, 0], [[0, 4], [[0, 0, 4, 0], [1, 1, 9, 0]], 0, 0], [[0, 4], [[0, 0, 4, 0], [1, 1, 9, 0]], 0, 0], [[0, 4], [[0, 0, 9, 0], [1, 0, 9, 0]], 0, 0], [[0, 9], [[0, 0, 9, 0]], 0, 0], [[0, 9], [[0, 0, 9, 0]], 0, 0], [[0, 9], [[0, 0, 9, 0]], 0, 0], [[0, 9], [[0, 1, 10, 0], [0, 0, 9, 0]], 0, 0], [[0, 9], [[0, 1, 11, 0], [0, 0, 9, 0], [1, 2, 10, 0]], 0, 0], [[2, 10], [[0, 0, 9, 0], [1, 1, 11, 0], [2, 0, 9, 0]], 0, 0], [[0, 9], [[0, 0, 9, 0], [1, 1, 11, 0]], 0, 0], [[0, 9], [[0, 0, 9, 0], [1, 1, 11, 0]], 0, 0], [[0, 9], [[0, 0, 9, 0], [1, 1, 11, 0]], 0, 0], [[1, 11], [[0, 0, 9, 0], [1, 0, 9, 0], [1, 1, 11, 0]], 0, 0], [[1, 11], [[0, 0, 9, 0], [1, 1, 11, 0]], 0, 0], [[0, 9], [[0, 0, 9, 0], [1, 1, 11, 0]], 0, 0], [[0, 9], [[0, 0, 9, 0], [1, 1, 11, 0]], 0, 0], [[0, 9], [[0, 0, 9, 0], [1, 1, 11, 0]], 0, 0], [[0, 9], [[0, 0, 9, 0], [1, 1, 11, 0]], 0, 0], [[0, 9], [[0, 1, 11, 0], [0, 0, 9, 0], [1, 1, 11, 0]], 0, 0], [[0, 9], [[0, 0, 9, 0], [1, 1, 11, 0]], 0, 0], [[1, 11], [[0, 0, 9, 0], [1, 0, 9, 0]], 0, 0], [[0, 9], [[0, 0, 9, 0]], 0, 0], [[0, 9], [[0, 0, 9, 0]], 0, 0], [[0, 9], [[0, 0, 9, 0]], 0, 0], [[0, 9], [[0, 0, 9, 0]], 0, 0], [[0, 9], [[0, 0, 9, 0]], 0, 0], [[0, 9], [[0, 0, 9, 0]], 0, 0], [[0, 9], [[0, 0, 9, 0]], 0, 0], [[0, 9], [[0, 0, 9, 0]], 0, 0], [[0, 9], [[0, 0, 9, 0]], 0, 0], [[0, 9], [[0, 0, 9, 0]], 0, 0], [[0, 9], [[0, 0, 9, 0]], 0, 0]];""")
 

	
 
#        response.mustcontain(
 
#            """<div id="changed_total_5e204e7583b9c8e7b93a020bd036564b1e731dae" """
 
#            """style="float:right;" class="changed_total tooltip" """
 
#            """title="Affected number of files, click to show """
 
#            """more details">3</div>"""
 
#        )
 

	
 
    def test_index_pagination_git(self):
 
        self.log_user()
 
        #pagination
 
        self.app.get(url(controller='changelog', action='index',
 
                                    repo_name=GIT_REPO), {'page': 1})
 
        self.app.get(url(controller='changelog', action='index',
 
                                    repo_name=GIT_REPO), {'page': 2})
 
        self.app.get(url(controller='changelog', action='index',
 
                                    repo_name=GIT_REPO), {'page': 3})
 
        self.app.get(url(controller='changelog', action='index',
 
                                    repo_name=GIT_REPO), {'page': 4})
 
        self.app.get(url(controller='changelog', action='index',
 
                                    repo_name=GIT_REPO), {'page': 5})
 
        response = self.app.get(url(controller='changelog', action='index',
 
                                    repo_name=GIT_REPO), {'page': 6, 'size': 20})
 

	
0 comments (0 inline, 0 general)