Kiln » TortoiseHg » TortoiseHg
Clone URL:  
Pushed to one repository · View In Graph Contained in 0.9, 0.9.1, and 0.9.1.1

logview: move row color logic to treemodel

Changeset ed1241d1c22d

Parent 497016c1efd6

by Steve Borho

Changes to 2 files · Browse files at ed1241d1c22d Showing diff from parent 497016c1efd6 Diff from another changeset...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
 
44
45
46
47
48
49
50
51
52
53
54
 
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
 
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
 
43
44
45
46
47
48
 
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
 
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
 # treemodel.py - changelog viewer data model  #  # Copyright 2008 Steve Borho <steve@borho.org>  #  # This software may be used and distributed according to the terms of the  # GNU General Public License version 2, incorporated herein by reference.    ''' Mercurial revision DAG visualization library     Implements a gtk.TreeModel which visualizes a Mercurial repository   revision history.    Portions of this code stolen mercilessly from bzr-gtk visualization  dialog. Other portions stolen from graphlog extension.  '''    import gtk  import gobject  from mercurial import util, templatefilters  from tortoisehg.util import hglib  from tortoisehg.hgtk import gtklib    # treemodel row enumerated attributes  LINES = 0 # These elements come from the changelog walker  GRAPHNODE = 1  REVID = 2  LAST_LINES = 3  WFILE = 4    BRANCH = 5 # calculated on demand, not cached  HEXID = 6  LOCALTIME = 7  UTC = 8    MESSAGE = 9 # calculated on demand, cached  COMMITER = 10  TAGS = 11  FGCOLOR = 12  AGE = 13    class TreeModel(gtk.GenericTreeModel):   - def __init__ (self, repo, graphdata, color_func, outgoing, origtip, npreviews): + def __init__ (self, repo, graphdata, outgoing, origtip, npreviews):   gtk.GenericTreeModel.__init__(self)   self.repo = repo   self.outgoing = outgoing   self.revisions = {}   self.graphdata = graphdata - self.color_func = color_func   self.wcparents = [x.rev() for x in repo.parents()]   self.tagrevs = [repo[r].rev() for t, r in repo.tagslist()]   self.branchtags = repo.branchtags()   self.origtip = origtip   self.npreviews = npreviews + self.set_author_color()   self.hidetags = self.repo.ui.config(   'tortoisehg', 'hidetags', '').split()     def refresh(self):   repo = self.repo   oldtags, oldparents = self.tagrevs, self.wcparents   oldbranches = [repo[n].rev() for n in self.branchtags.values()]     repo.invalidate()   repo.dirstate.invalidate()     self.wcparents = [x.rev() for x in repo.parents()]   self.tagrevs = [repo[r].rev() for t, r in repo.tagslist()]   self.branchtags = repo.branchtags()   brevs = [repo[n].rev() for n in self.branchtags.values()]   allrevs = set(oldtags + oldparents + oldbranches +   brevs + self.wcparents + self.tagrevs)   for rev in allrevs:   if rev in self.revisions:   del self.revisions[rev]     def on_get_flags(self):   return gtk.TREE_MODEL_LIST_ONLY     def on_get_n_columns(self):   return 13     def on_get_column_type(self, index):   if index == GRAPHNODE: return gobject.TYPE_PYOBJECT   if index == LINES: return gobject.TYPE_PYOBJECT   if index == REVID: return int   if index == LAST_LINES: return gobject.TYPE_PYOBJECT   if index == WFILE: return str     if index == BRANCH: return str   if index == HEXID: return str   if index == LOCALTIME: return str   if index == UTC: return str     if index == MESSAGE: return str   if index == COMMITER: return str   if index == TAGS: return str   if index == FGCOLOR: return str   if index == AGE: return str     def on_get_iter(self, path):   return path[0]     def on_get_path(self, rowref):   return rowref     def on_get_value(self, rowref, column):   (revid, graphnode, lines, path) = self.graphdata[rowref]     if column == REVID: return revid   if column == LINES: return lines   if column == LAST_LINES:   if rowref>0:   return self.graphdata[rowref-1][2]   return []   if column == WFILE: return path or ''     if column in (HEXID, BRANCH, LOCALTIME, UTC):   try:   ctx = self.repo[revid]   except IndexError:   return None   if column == HEXID:   return str(ctx)   if column == BRANCH:   return ctx.branch()   if column == LOCALTIME:   return hglib.displaytime(ctx.date())   if column == UTC:   return hglib.utctime(ctx.date())     if revid not in self.revisions:   try:   ctx = self.repo[revid]   except IndexError:   return None     # convert to Unicode for valid string operations   summary = hglib.tounicode(ctx.description()).replace(u'\0', '')   if self.repo.ui.configbool('tortoisehg', 'longsummary'):   limit = 80   lines = summary.splitlines()   if lines:   summary = lines.pop(0)   while len(summary) < limit and lines:   summary += u' ' + lines.pop(0)   summary = summary[0:limit]   else:   summary = ''   else:   lines = summary.splitlines()   summary = lines and lines[0] or ''   summary = gtklib.markup_escape_text(hglib.toutf(summary))   node = ctx.node()   tags = self.repo.nodetags(node)   taglist = hglib.toutf(', '.join(tags))   tstr = ''   for tag in tags:   if tag not in self.hidetags:   tstr += '<span color="%s" background="%s"> %s </span> ' % \   ('black', '#ffffaa', tag)     branch = ctx.branch()   bstr = ''   if self.branchtags.get(branch) == node:   bstr += '<span color="%s" background="%s"> %s </span> ' % \   ('black', '#aaffaa', branch)     author = hglib.toutf(hglib.username(ctx.user()))   age = templatefilters.age(ctx.date())   - color = self.color_func(ctx.parents(), revid, author) + color = self.color_func(revid, author)   if revid in self.wcparents:   sumstr = bstr + tstr + '<b><u>' + summary + '</u></b>'   else:   sumstr = bstr + tstr + summary     if node in self.outgoing:   marker = hglib.toutf(u'\u2191 ') # up arrow   sumstr = marker + sumstr   status = -1   elif revid >= self.origtip:   if revid >= len(self.repo) - self.npreviews:   marker = hglib.toutf(u'\u2193 ') # down arrow   sumstr = marker + sumstr   status = 2   else:   status = 1   else:   status = 0     revision = (sumstr, author, taglist, color, age, status)   self.revisions[revid] = revision   else:   revision = self.revisions[revid]   if column == GRAPHNODE:   column, color = graphnode   return (column, color, revision[5])   else:   return revision[column-MESSAGE]     def on_iter_next(self, rowref):   if rowref < len(self.graphdata) - 1:   return rowref+1   return None     def on_iter_children(self, parent):   if parent is None: return 0   return None     def on_iter_has_child(self, rowref):   return False     def on_iter_n_children(self, rowref):   if rowref is None: return len(self.graphdata)   return 0     def on_iter_nth_child(self, parent, n):   if parent is None: return n   return None     def on_iter_parent(self, child):   return None + + def set_author_color(self): + # If user has configured authorcolor in [tortoisehg], color + # rows by author matches + self.author_pats = [] + self.color_func = self.text_color_default + + if self.repo is not None: + for k, v in self.repo.ui.configitems('tortoisehg'): + if not k.startswith('authorcolor.'): continue + pat = k[12:] + self.author_pats.append((re.compile(pat, re.I), v)) + if self.author_pats or self.repo.ui.configbool('tortoisehg', + 'authorcolor'): + self.color_func = self.text_color_author + + def text_color_default(self, rev, author): + return int(rev) >= self.origtip and 'darkgreen' or 'black' + + colors = '''black blue deeppink mediumorchid blue burlywood4 goldenrod + slateblue red2 navy dimgrey'''.split() + color_cache = {} + + def text_color_author(self, rev, author): + if int(rev) >= self.origtip: + return 'darkgreen' + for re, v in self.author_pats: + if (re.search(author)): + return v + if author not in self.color_cache: + color = self.colors[len(self.color_cache.keys()) % len(self.colors)] + self.color_cache[author] = color + return self.color_cache[author] +
 
137
138
139
140
141
142
143
 
249
250
251
252
253
 
254
255
256
 
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
 
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
 
137
138
139
 
140
141
142
 
248
249
250
 
 
251
252
253
254
 
369
370
371
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
372
373
374
375
376
377
 
378
379
380
 
525
526
527
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
528
529
530
@@ -137,7 +137,6 @@
  def set_repo(self, repo, pbar=None):   self.repo = repo   self.pbar = pbar - self.set_author_color()     def search_in_tree(self, model, column, key, iter, data):   """Searches all fields shown in the tree when the user hits crtr+f, @@ -249,8 +248,7 @@
    if not self.model:   model = treemodel.TreeModel(self.repo, self.graphdata, - self.color_func, self.outgoing, self.origtip, - self.npreviews) + self.outgoing, self.origtip, self.npreviews)   self.treeview.set_model(model)   self.model = model   @@ -371,28 +369,12 @@
  self.treeview.set_model(None)   self.pbar.set_status_text(_('Repository is empty'))   - def set_author_color(self): - # If user has configured authorcolor in [tortoisehg], color - # rows by author matches - self.author_pats = [] - self.color_func = self.text_color_default - - if self.repo is not None: - for k, v in self.repo.ui.configitems('tortoisehg'): - if not k.startswith('authorcolor.'): continue - pat = k[12:] - self.author_pats.append((re.compile(pat, re.I), v)) - if self.author_pats or self.repo.ui.configbool('tortoisehg', - 'authorcolor'): - self.color_func = self.text_color_author -   def construct_treeview(self):   self.treeview = gtk.TreeView()   self.treeview.set_rules_hint(True)   self.treeview.set_reorderable(False)   self.treeview.set_enable_search(True)   self.treeview.set_search_equal_func(self.search_in_tree, None) - self.set_author_color()     self.treeview.get_selection().set_mode(gtk.SELECTION_SINGLE)   self.treeview.connect("cursor-changed", self._on_selection_changed) @@ -543,39 +525,6 @@
  def get_columns(self):   return self.columns   - def text_color_orig(self, parents, rev, author): - if int(rev) >= self.origtip: - return 'darkgreen' - if len(parents) == 2: - # mark merge changesets blue - return 'blue' - elif len(parents) == 1: - # detect non-trivial parent - if long(rev) != parents[0].rev()+1: - return '#900000' - else: - return 'black' - else: - return 'black' - - def text_color_default(self, parents, rev, author): - return int(rev) >= self.origtip and 'darkgreen' or 'black' - - colors = '''black blue deeppink mediumorchid blue burlywood4 goldenrod - slateblue red2 navy dimgrey'''.split() - color_cache = {} - - def text_color_author(self, parents, rev, author): - if int(rev) >= self.origtip: - return 'darkgreen' - for re, v in self.author_pats: - if (re.search(author)): - return v - if author not in self.color_cache: - color = self.colors[len(self.color_cache.keys()) % len(self.colors)] - self.color_cache[author] = color - return self.color_cache[author] -   def _on_selection_changed(self, treeview):   """callback for when the treeview changes."""   (path, focus) = treeview.get_cursor()