# HG changeset patch
# User Henrik Stuart <h...@hstuart.dk>
# Date 1249157376 -7200
# Node ID 8d769eb5217c948e6fb9025fada79bd41ccb9d7a
# Parent  8dc936698cf9e15f8fbeabf2aa38384a8e808d89
logview: support coloring by branch name

diff -r 8dc936698cf9 -r 8d769eb5217c hggtk/history.py
--- a/hggtk/history.py  Sat Aug 01 00:21:38 2009 -0500
+++ b/hggtk/history.py  Sat Aug 01 22:09:36 2009 +0200
@@ -194,6 +194,12 @@
         button.set_active(self.showcol.get('branch', False))
         button.set_draw_as_radio(True)
         menu.append(button)
+        button = gtk.CheckMenuItem(_('Color by Branch'))
+        button.connect('toggled', self._branch_color,
+                'branch-color')
+        button.set_active(self.branch_color)
+        button.set_draw_as_radio(True)
+        menu.append(button)
         menu.show_all()
         return menu
 
@@ -291,6 +297,7 @@
         settings = gdialog.GDialog.save_settings(self)
         settings['glog-vpane'] = self.vpaned.get_position()
         settings['glog-hpane'] = self.hpaned.get_position()
+        settings['branch-color'] = self.graphview.get_property('branch-color')
         for col in ('rev', 'date', 'id', 'branch', 'utc'):
             vis = self.graphview.get_property(col+'-column-visible')
             settings['glog-vis-'+col] = vis
@@ -321,6 +328,7 @@
         try:
             self.setting_vpos = settings['glog-vpane']
             self.setting_hpos = settings['glog-hpane']
+            self.branch_color = settings.get('branch-color', False)
             for col in ('rev', 'date', 'id', 'branch', 'utc'):
                 vis = settings['glog-vis-'+col]
                 self.showcol[col] = vis
@@ -332,6 +340,12 @@
         if self.graphview.model:
             self.graphview.model.refresh()
 
+    def _branch_color(self, button, property):
+        active = button.get_active()
+        self.graphview.set_property(property, active)
+        if hasattr(self, 'nextbutton'):
+            self.reload_log()
+
     def reload_log(self, **filteropts):
         'Send refresh event to treeview object'
         os.chdir(self.repo.root)  # for paths relative to repo root
diff -r 8dc936698cf9 -r 8d769eb5217c hggtk/logview/revgraph.py
--- a/hggtk/logview/revgraph.py Sat Aug 01 00:21:38 2009 -0500
+++ b/hggtk/logview/revgraph.py Sat Aug 01 22:09:36 2009 +0200
@@ -9,12 +9,24 @@
 __author__    = "Joel Rosdahl <j...@rosdahl.net>, Steve Borho 
<st...@borho.org>"
 
 from mercurial.node import nullrev
-from mercurial import cmdutil, util, ui
+from mercurial import cmdutil, util
 
 def __get_parents(repo, rev):
     return [x for x in repo.changelog.parentrevs(rev) if x != nullrev]
 
-def revision_grapher(repo, start_rev, stop_rev, branch=None, noheads=False):
+def _color_of(repo, rev, nextcolor, preferredcolor, branch_color=False):
+    if not branch_color:
+        if preferredcolor[0]:
+            rv = preferredcolor[0]
+            preferredcolor[0] = None
+        else:
+            rv = nextcolor[0]
+            nextcolor[0] = nextcolor[0] + 1
+        return rv
+    else:
+        return sum([ord(c) for c in repo[rev].branch()])
+
+def revision_grapher(repo, start_rev, stop_rev, branch=None, noheads=False, 
branch_color=False):
     """incremental revision grapher
 
     This generator function walks through the revision history from
@@ -33,7 +45,7 @@
     curr_rev = start_rev
     revs = []
     rev_color = {}
-    nextcolor = 0
+    nextcolor = [0]
     while curr_rev >= stop_rev:
         # Compute revs and next_revs.
         if curr_rev not in revs:
@@ -47,30 +59,29 @@
                     continue
             # New head.
             revs.append(curr_rev)
-            rev_color[curr_rev] = curcolor = nextcolor ; nextcolor += 1
+            rev_color[curr_rev] = _color_of(repo, curr_rev, nextcolor, [None], 
branch_color)
             r = __get_parents(repo, curr_rev)
             while r:
                 r0 = r[0]
                 if r0 < stop_rev: break
                 if r0 in rev_color: break
-                rev_color[r0] = curcolor
+                if not branch_color:
+                    rev_color[r0] = rev_color[curr_rev]
+                else:
+                    rev_color[r0] = _color_of(repo, r0, None, None, True)
                 r = __get_parents(repo, r0)
-        curcolor = rev_color[curr_rev]
         rev_index = revs.index(curr_rev)
         next_revs = revs[:]
 
         # Add parents to next_revs.
         parents = __get_parents(repo, curr_rev)
         parents_to_add = []
-        preferred_color = curcolor
+        preferred_color = [rev_color[curr_rev]]
         for parent in parents:
             if parent not in next_revs:
                 parents_to_add.append(parent)
                 if parent not in rev_color:
-                    if preferred_color:
-                        rev_color[parent] = preferred_color; preferred_color = 
None
-                    else:
-                        rev_color[parent] = nextcolor ; nextcolor += 1
+                    rev_color[parent] = _color_of(repo, parent, nextcolor, 
preferred_color, branch_color)
         next_revs[rev_index:rev_index + 1] = parents_to_add
 
         lines = []
@@ -83,7 +94,7 @@
                     color = rev_color[parent]
                     lines.append( (i, next_revs.index(parent), color) )
 
-        yield (curr_rev, (rev_index, curcolor), lines, parents)
+        yield (curr_rev, (rev_index, rev_color[curr_rev]), lines, parents)
         revs = next_revs
         curr_rev -= 1
 
diff -r 8dc936698cf9 -r 8d769eb5217c hggtk/logview/treeview.py
--- a/hggtk/logview/treeview.py Sat Aug 01 00:21:38 2009 -0500
+++ b/hggtk/logview/treeview.py Sat Aug 01 22:09:36 2009 +0200
@@ -84,6 +84,11 @@
                                  'Show branch',
                                  False,
                                  gobject.PARAM_READWRITE),
+        'branch-color': (gobject.TYPE_BOOLEAN,
+                                 'Branch color',
+                                 'Color by branch',
+                                 False,
+                                 gobject.PARAM_READWRITE)
     }
 
     __gsignals__ = {
@@ -111,6 +116,7 @@
         self.construct_treeview()
         self.pbar = pbar
         self.origtip = None
+        self.branch_color = False
 
     def set_repo(self, repo, pbar=None):
         self.repo = repo
@@ -160,7 +166,7 @@
                 start = len(self.repo.changelog) - 1
             noheads = opts.get('noheads', False)
             self.grapher = revision_grapher(self.repo, start, end, pats,
-                    noheads)
+                    noheads, self.branch_color)
         elif opts.get('revs', None):
             self.grapher = dumb_log_generator(self.repo, opts['revs'])
         else:
@@ -240,6 +246,8 @@
             return self.rev_column.get_visible()
         elif property.name == 'branch-column-visible':
             return self.branch_column.get_visible()
+        elif property.name == 'branch-color':
+            return self.branch_color
         elif property.name == 'utc-column-visible':
             return self.utc_column.get_visible()
         elif property.name == 'repo':
@@ -262,6 +270,8 @@
             self.rev_column.set_visible(value)
         elif property.name == 'branch-column-visible':
             self.branch_column.set_visible(value)
+        elif property.name == 'branch-color':
+            self.branch_color = value
         elif property.name == 'utc-column-visible':
             self.utc_column.set_visible(value)
         elif property.name == 'repo':

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Tortoisehg-develop mailing list
Tortoisehg-develop@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tortoisehg-develop

Reply via email to