Kiln » TortoiseHg » TortoiseHg
Clone URL:  
Pushed to one repository · View In Graph Contained in 1.9, 1.9.1, and 1.9.2

repomodel: drop hgview HgConfig() class

Also drop old username/alias logic.

Changeset 9e5318ce20a5

Parent 23f7b1ba052a

by Steve Borho

Changes to 2 files · Browse files at 9e5318ce20a5 Showing diff from parent 23f7b1ba052a Diff from another changeset...

Change 1 of 1 Show Entire File tortoisehg/​hgqt/​config.py Stacked
 
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
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
@@ -1,278 +0,0 @@
-# -*- coding: utf-8 -*- -# Copyright (c) 2003-2010 LOGILAB S.A. (Paris, FRANCE). -# http://www.logilab.fr/ -- mailto:contact@logilab.fr -# -# This program is free software; you can redistribute it and/or modify it under -# the terms of the GNU General Public License as published by the Free Software -# Foundation; either version 2 of the License, or (at your option) any later -# version. -# -# This program is distributed in the hope that it will be useful, but WITHOUT -# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS -# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License along with -# this program; if not, write to the Free Software Foundation, Inc., -# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -# -# pylint: disable-msg=C0103 - -""" -Module for managing configuration parameters of hgview using Hg's -configuration system -""" -import os -import re - -def cached(meth): - """ - decorator to cache config values once they are read - """ - name = meth.func_name - def wrapper(self, *args, **kw): - if name in self._cache: - return self._cache[name] - res = meth(self, *args, **kw) - self._cache[name] = res - return res - wrapper.__doc__ = meth.__doc__ - return wrapper - -class HgConfig(object): - """ - Class managing user configuration from hg standard configuration system (.hgrc) - """ - def __init__(self, ui, section="TortoiseHgQt"): - self.ui = ui - self.section = section - self._cache = {} - - @cached - def getFont(self): - """ - font: default font used to display diffs and files. Use Qt4 format. - """ - return self.ui.config(self.section, 'font', 'Monospace') - - @cached - def getFontSize(self, default=10): - """ - fontsize: text size in file content viewer - """ - return int(self.ui.config(self.section, 'fontsize', default)) - - @cached - def getDotRadius(self, default=8): - """ - dotradius: radius (in pixels) of the dot in the revision graph - """ - r = self.ui.config(self.section, 'dotradius', default) - return int(r) - - @cached - def getUsers(self): - """ - users: path of the file holding users configurations - """ - users = {} - aliases = {} - usersfile = self.ui.config(self.section, 'users', - os.path.join('~', ".hgusers")) - cfgfile = None - if usersfile: - try: - cfgfile = open(os.path.expanduser(usersfile)) - except IOError: - cfgfile = None - - if cfgfile: - currid = None - for line in cfgfile: - line = line.strip() - if not line or line.startswith('#'): - continue - cmd, val = line.split('=', 1) - if cmd == 'id': - currid = val - if currid in users: - print "W: user %s is defined several times" % currid - users[currid] = {'aliases': set()} - elif cmd == "alias": - users[currid]['aliases'].add(val) - if val in aliases: - print ("W: alias %s is used in several " - "user definitions" % val) - aliases[val] = currid - else: - users[currid][cmd] = val - return users, aliases - - @cached - def getFileModifiedColor(self, default='blue'): - """ - filemodifiedcolor: display color of a modified file - """ - return self.ui.config(self.section, 'filemodifiedcolor', default) - @cached - def getFileRemovedColor(self, default='red'): - """ - fileremovedcolor: display color of a removed file - """ - return self.ui.config(self.section, 'fileremovededcolor', default) - @cached - def getFileDeletedColor(self, default='darkred'): - """ - filedeletedcolor: display color of a deleted file - """ - return self.ui.config(self.section, 'filedeletedcolor', default) - @cached - def getFileAddedColor(self, default='green'): - """ - fileaddedcolor: display color of an added file - """ - return self.ui.config(self.section, 'fileaddedcolor', default) - - @cached - def getRowHeight(self, default=20): - """ - rowheight: height (in pixels) on a row of the revision table - """ - return int(self.ui.config(self.section, 'rowheight', default)) - - @cached - def getHideFindDelay(self, default=10000): - """ - hidefinddelay: delay (in ms) after which the find bar will disappear - """ - return int(self.ui.config(self.section, 'hidefindddelay', default)) - - @cached - def getFillingStep(self, default=300): - """ - fillingstep: number of nodes 'loaded' at a time when updating repo graph log - """ - return int(self.ui.config(self.section, 'fillingstep', default)) - - @cached - def getChangelogColumns(self, default=None): - """ - changelogcolumns: ordered list of displayed columns in changelog views; - defaults to ID, Branch, Log, Author, Date, Tags - """ - cols = self.ui.config(self.section, 'changelogcolumns', default) - if cols is None: - return None - return [col.strip() for col in cols.split(',') if col.strip()] - - @cached - def getFilelogColumns(self, default=None): - """ - filelogcolumns: ordered list of displayed columns in filelog views; - defaults to ID, Log, Author, Date - """ - cols = self.ui.config(self.section, 'filelogcolumns', default) - if cols is None: - return None - return [col.strip() for col in cols.split(',') if col.strip()] - - @cached - def getDisplayDiffStats(self, default="no"): - """ - displaydiffstats: flag controllong the appearance of the - 'Diff' column in a revision's file list - """ - val = str(self.ui.config(self.section, 'displaydiffstats', default)) - return val.lower() in ['true', 'yes', '1', 'on'] - - @cached - def getMaxFileSize(self, default=100000): - """ - maxfilesize: max size of a file (for diff computations, display content, etc.) - """ - return int(self.ui.config(self.section, 'maxfilesize', default)) - - @cached - def getDiffBGColor(self, default='white'): - """ - diffbgcolor: background color of diffs - """ - return self.ui.config(self.section, 'diffbgcolor', default) - - @cached - def getDiffFGColor(self, default='black'): - """ - difffgcolor: text color of diffs - """ - return self.ui.config(self.section, 'difffgcolor', default) - - @cached - def getDiffPlusColor(self, default='#006400'): - """ - diffpluscolor: text color of added lines in diffs - """ - return self.ui.config(self.section, 'diffpluscolor', default) - - @cached - def getDiffMinusColor(self, default='#900000'): - """ - diffminuscolor: text color of removed lines in diffs - """ - return self.ui.config(self.section, 'diffminuscolor', default) - - @cached - def getDiffSectionColor(self, default='blue'): - """ - diffsectioncolor: text color of new section in diffs - """ - return self.ui.config(self.section, 'diffsectioncolor', default) - - @cached - def getMQFGColor(self, default='#ff8183'): - """ - mqfgcolor: bg color to highlight mq patches - """ - return self.ui.config(self.section, 'mqfgcolor', default) - - @cached - def getMQHideTags(self, default=False): - """ - mqhidetags: hide mq tags - """ - return self.ui.config(self.section, 'mqhidetags', default) - - - -_HgConfig = HgConfig -# HgConfig is instanciated only once (singleton) -# -# this 'factory' is used to manage this (not using heavy guns of -# metaclass or so) -_hgconfig = None -def HgConfig(ui): - """Factory to instanciate HgConfig class as a singleton - """ - # pylint: disable-msg=E0102 - global _hgconfig - if _hgconfig is None: - _hgconfig = _HgConfig(ui) - return _hgconfig - - -def get_option_descriptions(rest=False): - """ - Extract options descriptions (docstrings of HgConfig methods) - """ - options = [] - for attr in dir(_HgConfig): - if attr.startswith('get'): - meth = getattr(_HgConfig, attr) - if callable(meth): - doc = meth.__doc__ - if doc and doc.strip(): - doc = doc.strip() - if rest: - doc = re.sub(r' *(?P<arg>.*) *: *(?P<desc>.*)', r'``\1`` \2', doc.strip()) - doc = ' '.join(doc.split()) # remove \n and other multiple whitespaces - options.append(doc) - return options -
 
20
21
22
23
24
25
26
 
147
148
149
150
 
151
152
153
 
155
156
157
158
 
159
160
161
 
242
243
244
245
246
247
248
249
250
251
252
 
 
 
 
 
 
253
254
255
 
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
 
 
 
283
284
285
286
287
288
289
290
 
303
304
305
306
307
 
 
308
309
310
311
312
313
 
314
315
316
317
 
318
319
320
 
20
21
22
 
23
24
25
 
146
147
148
 
149
150
151
152
 
154
155
156
 
157
158
159
160
 
241
242
243
 
 
 
 
 
 
 
 
244
245
246
247
248
249
250
251
252
 
265
266
267
 
 
 
 
 
 
 
 
 
 
 
 
268
269
270
271
272
 
 
 
273
274
275
 
288
289
290
 
 
291
292
293
294
295
296
297
 
298
299
300
301
 
302
303
304
305
@@ -20,7 +20,6 @@
   from tortoisehg.hgqt.graph import Graph  from tortoisehg.hgqt.graph import revision_grapher -from tortoisehg.hgqt.config import HgConfig  from tortoisehg.hgqt.qtlib import geticon    from tortoisehg.hgqt.i18n import _ @@ -147,7 +146,7 @@
  self._fill_timer = None   self.rowcount = 0   self.repo = repo - self.load_config() + self.reloadConfig()   self.setRepo(repo, branch=branch)     def setRepo(self, repo, branch=''): @@ -155,7 +154,7 @@
  self.repo = repo   self._branch = branch   if oldrepo.root != repo.root: - self.load_config() + self.reloadConfig()   self._datacache = {}   try:   wdctxs = self.repo.changectx(None).parents() @@ -242,14 +241,12 @@
  def columnCount(self, parent=None):   return len(self._columns)   - def load_config(self): - cfg = HgConfig(self.repo.ui) - self._users, self._aliases = cfg.getUsers() - self.dot_radius = cfg.getDotRadius(default=8) - self.rowheight = cfg.getRowHeight() - self.fill_step = cfg.getFillingStep() - self.max_file_size = cfg.getMaxFileSize() - self.hide_mq_tags = cfg.getMQHideTags() + def reloadConfig(self): + self.dot_radius = 8 + self.rowheight = 20 + self.fill_step = 500 # use hgtk logic + self.max_file_size = 1024*1024 # will be removed + self.hide_mq_tags = False # use hgtk logic   self.updateColumns()     def updateColumns(self): @@ -268,23 +265,11 @@
  return None     def user_color(self, user): - if user in self._aliases: - user = self._aliases[user] - if user in self._users: - try: - color = self._users[user]['color'] - color = QColor(color).name() - self._user_colors[user] = color - except: - pass - if user not in self._user_colors: - self._user_colors[user] = get_color(len(self._user_colors), - self._user_colors.values()) + 'deprecated, please replace with hgtk color scheme' + self._user_colors[user] = get_color(len(self._user_colors), + self._user_colors.values())   return self._user_colors[user]   - def user_name(self, user): - return self._aliases.get(user, user) -   def namedbranch_color(self, branch):   if branch not in self._branch_colors:   self._branch_colors[branch] = get_color(len(self._branch_colors)) @@ -303,18 +288,18 @@
  gnode = self.graph[row]   ctx = self.repo.changectx(gnode.rev)   if role == Qt.DisplayRole: - if column == 'Author': #author - return QVariant(self.user_name(_columnmap[column](self, ctx, gnode))) + if column == 'Author': + return QVariant(_columnmap[column](self, ctx, gnode))   elif column == 'Log':   msg = _columnmap[column](self, ctx, gnode)   return QVariant(msg)   return QVariant(_columnmap[column](self, ctx, gnode))   elif role == Qt.ForegroundRole: - if column == 'Author': #author + if column == 'Author':   if self.authorcolor:   return QVariant(QColor(self.user_color(ctx.user())))   return nullvariant - if column == 'Branch': #branch + if column == 'Branch':   return QVariant(QColor(self.namedbranch_color(ctx.branch())))   elif role == Qt.DecorationRole:   if column == 'Graph':