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

create new module revpanelwidget

Changeset c95bf5415834

Parent 5b33a7d68c8a

by Adrian Buehlmann

Changes to 2 files · Browse files at c95bf5415834 Showing diff from parent 5b33a7d68c8a Diff from another changeset...

 
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
 
101
102
103
104
 
105
106
107
 
167
168
169
170
 
171
172
173
 
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
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
 
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
 
90
91
92
 
93
94
95
96
 
156
157
158
 
159
160
161
162
 
179
180
181
 
182
183
184
185
186
187
188
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
189
190
191
@@ -8,42 +8,31 @@
 # This software may be used and distributed according to the terms  # of the GNU General Public License, incorporated herein by reference.   -import sys, os -import re +import os   -from PyQt4 import QtCore, QtGui, Qsci +from PyQt4 import QtCore, QtGui   -from mercurial import ui, hg -from mercurial import util +from mercurial import hg   -from tortoisehg.util.util import tounicode, has_closed_branch_support -from tortoisehg.util.util import rootpath, find_repository +from tortoisehg.util.util import has_closed_branch_support    from tortoisehg.hgqt.i18n import _ -from tortoisehg.hgqt.graph import diff as revdiff -from tortoisehg.hgqt.decorators import timeit    from tortoisehg.hgqt import icon as geticon  from tortoisehg.hgqt.repomodel import HgRepoListModel  from tortoisehg.hgqt.filelistmodel import HgFileListModel -from tortoisehg.hgqt.filedialogs import FileLogDialog, FileDiffDialog -from tortoisehg.hgqt.manifestdialog import ManifestDialog  from tortoisehg.hgqt.update import UpdateDialog -from tortoisehg.hgqt import cmdui, csinfo, qtlib +from tortoisehg.hgqt import cmdui  from tortoisehg.hgqt.config import HgConfig    from revdisplay import RevMessage  from filelistview import HgFileListView  from fileview import HgFileView  from repoview import HgRepoView - -from tortoisehg.util import paths, hglib - -from mercurial.error import RepoError +from revpanelwidget import RevPanelWidget      Qt = QtCore.Qt -bold = QtGui.QFont.Bold  connect = QtCore.QObject.connect  SIGNAL = QtCore.SIGNAL   @@ -101,7 +90,7 @@
  self.hbox.setMargin(0)     self.revisions_splitter = QtGui.QSplitter(self) - self.revisions_splitter.setOrientation(QtCore.Qt.Vertical) + self.revisions_splitter.setOrientation(Qt.Vertical)     self.repoview = HgRepoView(self.revisions_splitter)   sp = SP(SP.Expanding, SP.Expanding) @@ -167,7 +156,7 @@
  self.message_splitter.setFrameShape(QtGui.QFrame.NoFrame)   self.message_splitter.setLineWidth(0)   self.message_splitter.setMidLineWidth(0) - self.message_splitter.setOrientation(QtCore.Qt.Vertical) + self.message_splitter.setOrientation(Qt.Vertical)   self.message_splitter.setOpaqueResize(True)   self.message = RevMessage(self.message_splitter)   @@ -190,130 +179,13 @@
  self.fileview.setSizePolicy(sp)   self.fileview.setMinimumSize(QtCore.QSize(0, 0))   - self.setupRevPanel() + self.revpanel = RevPanelWidget(self.repo, self.repoview)     cset_and_file_details_layout.addWidget(self.revpanel)   cset_and_file_details_layout.addWidget(self.message_splitter)     revisiondetails_layout.addWidget(self.filelist_splitter)   - def setupRevPanel(self): - def label_func(widget, item): - if item == 'cset': - return _('Changeset:') - elif item == 'parents': - return _('Parent:') - elif item == 'children': - return _('Child:') - elif item == 'patch': - return _('Patch:') - raise csinfo.UnknownItem(item) - def revid_markup(revid, **kargs): - opts = dict(family='monospace', size='9pt') - opts.update(kargs) - return qtlib.markup(revid, **opts) - def data_func(widget, item, ctx): - def summary_line(desc): - desc = desc.replace('\0', '').split('\n')[0] - return hglib.tounicode(desc[:80]) - def revline_data(ctx, hl=False, branch=None): - if isinstance(ctx, basestring): - return ctx - desc = ctx.description() - return (str(ctx.rev()), str(ctx), summary_line(desc), hl, branch) - if item == 'cset': - return revline_data(ctx) - elif item == 'branch': - value = hglib.tounicode(ctx.branch()) - return value != 'default' and value or None - elif item == 'parents': - # TODO: need to put 'diff to other' checkbox - #pindex = self.diff_other_parent() and 1 or 0 - pindex = 0 # always show diff with first parent - pctxs = ctx.parents() - parents = [] - for pctx in pctxs: - highlight = len(pctxs) == 2 and pctx == pctxs[pindex] - branch = None - if hasattr(pctx, 'branch') and pctx.branch() != ctx.branch(): - branch = pctx.branch() - parents.append(revline_data(pctx, highlight, branch)) - return parents - elif item == 'children': - children = [] - for cctx in ctx.children(): - branch = None - if hasattr(cctx, 'branch') and cctx.branch() != ctx.branch(): - branch = cctx.branch() - children.append(revline_data(cctx, branch=branch)) - return children - elif item in ('transplant', 'p4', 'svn'): - ts = widget.get_data(item, usepreset=True) - if not ts: - return None - try: - tctx = self.repo[ts] - return revline_data(tctx) - except (error.LookupError, error.RepoLookupError, error.RepoError): - return ts - elif item == 'patch': - if hasattr(ctx, '_patchname'): - desc = ctx.description() - return (ctx._patchname, str(ctx), summary_line(desc)) - return None - raise csinfo.UnknownItem(item) - def markup_func(widget, item, value): - def link_markup(revnum, revid, enable=True): - mrevid = revid_markup(revid) - if not enable: - return '%s (%s)' % (revnum, mrevid) - link = 'cset://%s:%s' % (revnum, revid) - return '<a href="%s">%s (%s)</a>' % (link, revnum, mrevid) - def revline_markup(revnum, revid, summary, highlight=None, - branch=None, link=True): - def branch_markup(branch): - opts = dict(fg='black', bg='#aaffaa') - return qtlib.markup(' %s ' % branch, **opts) - summary = qtlib.markup(summary) - if branch: - branch = branch_markup(branch) - if revid: - rev = link_markup(revnum, revid, link) - if branch: - return '%s %s %s' % (rev, branch, summary) - return '%s %s' % (rev, summary) - else: - revnum = qtlib.markup(revnum) - if branch: - return '%s - %s %s' % (revnum, branch, summary) - return '%s - %s' % (revnum, summary) - if item in ('cset', 'transplant', 'patch', 'p4', 'svn'): - link = item != 'cset' - if isinstance(value, basestring): - return revid_markup(value) - return revline_markup(link=link, *value) - elif item in ('parents', 'children'): - csets = [] - for cset in value: - if isinstance(cset, basestring): - csets.append(revid_markup(cset)) - else: - csets.append(revline_markup(*cset)) - return csets - raise csinfo.UnknownItem(item) - - custom = csinfo.custom(data=data_func, label=label_func, - markup=markup_func) - style = csinfo.panelstyle(contents=('cset', 'branch', 'user', - 'dateage', 'parents', 'children', 'tags', 'transplant', - 'p4', 'svn'), selectable=True, expandable=True) - self.revpanel = csinfo.create(self.repo, style=style, custom=custom) - def activated(url): - if url.startsWith('cset://'): - rev = url[7:].split(':')[0] - self.repoview.goto(rev) - self.revpanel.linkActivated.connect(activated) -   def load_config(self):   cfg = HgConfig(self.repo.ui)   fontstr = cfg.getFont()
Change 1 of 1 Show Entire File tortoisehg/​hgqt/​revpanelwidget.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
@@ -0,0 +1,142 @@
+# -*- coding: iso-8859-1 -*- +#!/usr/bin/env python +# repowidget.py - TortoiseHg repository widget +# +# Copyright (C) 2007-2010 Logilab. All rights reserved. +# Copyright (C) 2010 Adrian Buehlmann <adrian@cadifra.com> +# +# This software may be used and distributed according to the terms +# of the GNU General Public License, incorporated herein by reference. + + +from tortoisehg.hgqt.i18n import _ + +from tortoisehg.hgqt import csinfo, qtlib + +from tortoisehg.util import hglib + +from mercurial.error import RepoError + + +def RevPanelWidget(repo, repoview): + '''creates a rev panel widget and returns it + + repoview is a HgRepoView object''' + + def label_func(widget, item): + if item == 'cset': + return _('Changeset:') + elif item == 'parents': + return _('Parent:') + elif item == 'children': + return _('Child:') + elif item == 'patch': + return _('Patch:') + raise csinfo.UnknownItem(item) + def revid_markup(revid, **kargs): + opts = dict(family='monospace', size='9pt') + opts.update(kargs) + return qtlib.markup(revid, **opts) + def data_func(widget, item, ctx): + def summary_line(desc): + desc = desc.replace('\0', '').split('\n')[0] + return hglib.tounicode(desc[:80]) + def revline_data(ctx, hl=False, branch=None): + if isinstance(ctx, basestring): + return ctx + desc = ctx.description() + return (str(ctx.rev()), str(ctx), summary_line(desc), hl, branch) + if item == 'cset': + return revline_data(ctx) + elif item == 'branch': + value = hglib.tounicode(ctx.branch()) + return value != 'default' and value or None + elif item == 'parents': + # TODO: need to put 'diff to other' checkbox + #pindex = self.diff_other_parent() and 1 or 0 + pindex = 0 # always show diff with first parent + pctxs = ctx.parents() + parents = [] + for pctx in pctxs: + highlight = len(pctxs) == 2 and pctx == pctxs[pindex] + branch = None + if hasattr(pctx, 'branch') and pctx.branch() != ctx.branch(): + branch = pctx.branch() + parents.append(revline_data(pctx, highlight, branch)) + return parents + elif item == 'children': + children = [] + for cctx in ctx.children(): + branch = None + if hasattr(cctx, 'branch') and cctx.branch() != ctx.branch(): + branch = cctx.branch() + children.append(revline_data(cctx, branch=branch)) + return children + elif item in ('transplant', 'p4', 'svn'): + ts = widget.get_data(item, usepreset=True) + if not ts: + return None + try: + tctx = repo[ts] + return revline_data(tctx) + except (error.LookupError, error.RepoLookupError, error.RepoError): + return ts + elif item == 'patch': + if hasattr(ctx, '_patchname'): + desc = ctx.description() + return (ctx._patchname, str(ctx), summary_line(desc)) + return None + raise csinfo.UnknownItem(item) + def markup_func(widget, item, value): + def link_markup(revnum, revid, enable=True): + mrevid = revid_markup(revid) + if not enable: + return '%s (%s)' % (revnum, mrevid) + link = 'cset://%s:%s' % (revnum, revid) + return '<a href="%s">%s (%s)</a>' % (link, revnum, mrevid) + def revline_markup(revnum, revid, summary, highlight=None, + branch=None, link=True): + def branch_markup(branch): + opts = dict(fg='black', bg='#aaffaa') + return qtlib.markup(' %s ' % branch, **opts) + summary = qtlib.markup(summary) + if branch: + branch = branch_markup(branch) + if revid: + rev = link_markup(revnum, revid, link) + if branch: + return '%s %s %s' % (rev, branch, summary) + return '%s %s' % (rev, summary) + else: + revnum = qtlib.markup(revnum) + if branch: + return '%s - %s %s' % (revnum, branch, summary) + return '%s - %s' % (revnum, summary) + if item in ('cset', 'transplant', 'patch', 'p4', 'svn'): + link = item != 'cset' + if isinstance(value, basestring): + return revid_markup(value) + return revline_markup(link=link, *value) + elif item in ('parents', 'children'): + csets = [] + for cset in value: + if isinstance(cset, basestring): + csets.append(revid_markup(cset)) + else: + csets.append(revline_markup(*cset)) + return csets + raise csinfo.UnknownItem(item) + + custom = csinfo.custom(data=data_func, label=label_func, + markup=markup_func) + style = csinfo.panelstyle(contents=('cset', 'branch', 'user', + 'dateage', 'parents', 'children', 'tags', 'transplant', + 'p4', 'svn'), selectable=True, expandable=True) + revpanel = csinfo.create(repo, style=style, custom=custom) + def activated(url): + if url.startsWith('cset://'): + rev = url[7:].split(':')[0] + repoview.goto(rev) + revpanel.linkActivated.connect(activated) + + return revpanel